Contact Form In Directory Listing Questions

I am trying to add the contact form into my single-listing.php page but when I add the code (copy and paste) from the original single-listing.php page it removes a huge chunks of my custom single-listing.php page. See screen shots attached.

This is the code I am adding:

<div class="listing-contact-form">
  <div class="clear"></div>

<?php if( empty( $options['disable_contact_form'] ) ): ?>

<form method="post" action="#" class="contact-user-btn action-form" id="action-form">
	<input type="submit" name="contact_user" value="<?php _e('Contact User', $this->text_domain ); ?>" onclick="dr_listings.toggle_contact_form(); return false;" />
</form>

<div class="clear"></div>

<form method="post" action="#" class="standard-form base dr-contact-form" id="confirm-form">
	<?php
	global $current_user;

	$name   = ( isset( $current_user->display_name ) && '' != $current_user->display_name ) ? $current_user->display_name :
	( ( isset( $current_user->first_name ) && '' != $current_user->first_name ) ? $current_user->first_name : '' );
	$email  = ( isset( $current_user->user_email ) && '' != $current_user->user_email ) ? $current_user->user_email : '';
	?>
	<div class="editfield">
		<label for="name"><?php _e( 'Name', $this->text_domain ); ?> (<?php _e( 'required', $this->text_domain ); ?>)</label>
		<input type="text" id="name" name ="name" value="<?php echo ( isset( $_POST['name'] ) ) ? $_POST['name'] : $name; ?>" />
		<p class="description"><?php _e( 'Enter your full name here.', $this->text_domain ); ?></p>
	</div>
	<div class="editfield">
		<label for="email"><?php _e( 'Email', $this->text_domain ); ?> (<?php _e( 'required', $this->text_domain ); ?>)</label>
		<input type="text" id="email" name ="email" value="<?php echo ( isset( $_POST['email'] ) ) ? $_POST['email'] : $email; ?>" />
		<p class="description"><?php _e( 'Enter a valid email address here.', $this->text_domain ); ?></p>
	</div>
	<div class="editfield">
		<label for="subject"><?php _e( 'Subject', $this->text_domain ); ?> (<?php _e( 'required', $this->text_domain ); ?>)</label>
		<input type="text" id="subject" name ="subject" value="<?php echo ( isset( $_POST['subject'] ) ) ? $_POST['subject'] : ''; ?>" />
		<p class="description"><?php _e( 'Enter the subject of your enquiry here.', $this->text_domain ); ?></p>
	</div>
	<div class="editfield">
		<label for="message"><?php _e( 'Message', $this->text_domain ); ?> (<?php _e( 'required', $this->text_domain ); ?>)</label>
		<textarea id="message" name="message"><?php echo ( isset( $_POST['message'] ) ) ? $_POST['message'] : ''; ?></textarea>
		<p class="description"><?php _e( 'Enter the content of your enquiry here.', $this->text_domain ); ?></p>
	</div>

	<div class="editfield">
		<label for="dr_random_value"><?php _e( 'Security image', $this->text_domain ); ?> (<?php _e( 'required', $this->text_domain ); ?>)</label>
			<img class="captcha" src="<?php echo admin_url('admin-ajax.php?action=dr-captcha');?>" />
		<input type="text" id="dr_random_value" name ="dr_random_value" value="" size="8" />
		<p class="description"><?php _e( 'Enter the characters from the image.', $this->text_domain ); ?></p>
	</div>

	<div class="submit">
		<p>
			<?php wp_nonce_field( 'send_message' ); ?>
			<input type="submit" class="button confirm" value="<?php _e( 'Send', $this->text_domain ); ?>" name="contact_form_send" />
			<input type="submit" class="button cancel"  value="<?php _e( 'Cancel', $this->text_domain ); ?>" onclick="dr_listings.cancel_contact_form(); return false;" />
		</p>
	</div>

</form>

<?php endif; ?>

<div class="clear"></div>
</div>

I would love to have the same feature WPMUDEV has when contacting a pro. Simple button that says "Contact Me" and a link to a contact form.

Any thoughts on how to implement this?

Support access is granted if you want to login and take a look around.

Thanks
William

  • Rupok

    Hi William

    Hope you had a wonderful day.

    I just went to your site, then went to a listing page, but I could find all content showing there. So I assume, you have removed the "contact form" code already. I could tell you better if I could saw the issue in action. So if possible, can you add the code again and let us know so we can have a look at this?

    As a workaround, you can use our PopUp Pro plugin for showing contact form. With PopUp pro, you can fire a PopUp when user clicks on any specific element of the page (e.g. a button).

    Have a nice day. Cheers!
    Rupok

  • William

    Hi Kasia Swiderska

    When I changed

    $this->text_domain

    to

    _e( 'Send', 'classifieds' );

    I get a ton of syntax errors. Can you please help?

    I did a find and replace and this is my final code:

    <div class=&quot;listing-contact-form&quot;>
      <div class=&quot;clear&quot;></div>
    
    <?php if( empty( $options['disable_contact_form'] ) ): ?>
    
    <form method=&quot;post&quot; action=&quot;#&quot; class=&quot;contact-user-btn action-form&quot; id=&quot;action-form&quot;>
    	<input type=&quot;submit&quot; name=&quot;contact_user&quot; value=&quot;<?php _e('Contact User', _e( 'Send', 'classifieds' );  ); ?>&quot; onclick=&quot;dr_listings.toggle_contact_form(); return false;&quot; />
    </form>
    
    <div class=&quot;clear&quot;></div>
    
    <form method=&quot;post&quot; action=&quot;#&quot; class=&quot;standard-form base dr-contact-form&quot; id=&quot;confirm-form&quot;>
    	<?php
    	global $current_user;
    
    	$name   = ( isset( $current_user->display_name ) && '' != $current_user->display_name ) ? $current_user->display_name :
    	( ( isset( $current_user->first_name ) && '' != $current_user->first_name ) ? $current_user->first_name : '' );
    	$email  = ( isset( $current_user->user_email ) && '' != $current_user->user_email ) ? $current_user->user_email : '';
    	?>
    	<div class=&quot;editfield&quot;>
    		<label for=&quot;name&quot;><?php _e( 'Name', _e( 'Send', 'classifieds' );  ); ?> (<?php _e( 'required', _e( 'Send', 'classifieds' );  ); ?>)</label>
    		<input type=&quot;text&quot; id=&quot;name&quot; name =&quot;name&quot; value=&quot;<?php echo ( isset( $_POST['name'] ) ) ? $_POST['name'] : $name; ?>&quot; />
    		<p class=&quot;description&quot;><?php _e( 'Enter your full name here.', _e( 'Send', 'classifieds' );  ); ?></p>
    	</div>
    	<div class=&quot;editfield&quot;>
    		<label for=&quot;email&quot;><?php _e( 'Email', _e( 'Send', 'classifieds' );  ); ?> (<?php _e( 'required', _e( 'Send', 'classifieds' );  ); ?>)</label>
    		<input type=&quot;text&quot; id=&quot;email&quot; name =&quot;email&quot; value=&quot;<?php echo ( isset( $_POST['email'] ) ) ? $_POST['email'] : $email; ?>&quot; />
    		<p class=&quot;description&quot;><?php _e( 'Enter a valid email address here.', _e( 'Send', 'classifieds' );  ); ?></p>
    	</div>
    	<div class=&quot;editfield&quot;>
    		<label for=&quot;subject&quot;><?php _e( 'Subject', _e( 'Send', 'classifieds' );  ); ?> (<?php _e( 'required', _e( 'Send', 'classifieds' );  ); ?>)</label>
    		<input type=&quot;text&quot; id=&quot;subject&quot; name =&quot;subject&quot; value=&quot;<?php echo ( isset( $_POST['subject'] ) ) ? $_POST['subject'] : ''; ?>&quot; />
    		<p class=&quot;description&quot;><?php _e( 'Enter the subject of your enquiry here.', _e( 'Send', 'classifieds' );  ); ?></p>
    	</div>
    	<div class=&quot;editfield&quot;>
    		<label for=&quot;message&quot;><?php _e( 'Message', _e( 'Send', 'classifieds' );  ); ?> (<?php _e( 'required', _e( 'Send', 'classifieds' );  ); ?>)</label>
    		<textarea id=&quot;message&quot; name=&quot;message&quot;><?php echo ( isset( $_POST['message'] ) ) ? $_POST['message'] : ''; ?></textarea>
    		<p class=&quot;description&quot;><?php _e( 'Enter the content of your enquiry here.', _e( 'Send', 'classifieds' );  ); ?></p>
    	</div>
    
    	<div class=&quot;editfield&quot;>
    		<label for=&quot;dr_random_value&quot;><?php _e( 'Security image', _e( 'Send', 'classifieds' );  ); ?> (<?php _e( 'required', _e( 'Send', 'classifieds' );  ); ?>)</label>
    			<img class=&quot;captcha&quot; src=&quot;<?php echo admin_url('admin-ajax.php?action=dr-captcha');?>&quot; />
    		<input type=&quot;text&quot; id=&quot;dr_random_value&quot; name =&quot;dr_random_value&quot; value=&quot;&quot; size=&quot;8&quot; />
    		<p class=&quot;description&quot;><?php _e( 'Enter the characters from the image.', _e( 'Send', 'classifieds' );  ); ?></p>
    	</div>
    
    	<div class=&quot;submit&quot;>
    		<p>
    			<?php wp_nonce_field( 'send_message' ); ?>
    			<input type=&quot;submit&quot; class=&quot;button confirm&quot; value=&quot;<?php _e( 'Send', _e( 'Send', 'classifieds' );  ); ?>&quot; name=&quot;contact_form_send&quot; />
    			<input type=&quot;submit&quot; class=&quot;button cancel&quot;  value=&quot;<?php _e( 'Cancel', _e( 'Send', 'classifieds' );  ); ?>&quot; onclick=&quot;dr_listings.cancel_contact_form(); return false;&quot; />
    		</p>
    	</div>
    
    </form>
    
    <?php endif; ?>
    
    <div class=&quot;clear&quot;></div>
    </div>

    Thanks,
    William

  • William

    Hi Kasia Swiderska

    I have updated my code to the following and I am still having the same issue.

    http://myinsurancepage.com/listing/debbie-elmer/

    <div class="listing-contact-form">
      <?php if ( isset( $_POST['_wpnonce'] ) ): ?>
      <br clear="all" />
      <div id="dr-message-error">
        <?php _e( "Send message failed: you didn't fill all required fields correctly in contact form!", 'classifieds' ); ?>
      </div>
      <br clear="all" />
      <?php endif; ?>
      <?php if ( isset( $_GET['sent'] ) ):
    
    if(1 == $_GET['sent'] ): ?>
      <br clear="all" />
      <div id="dr-message">
        <?php _e( 'Message is sent!', 'classifieds' ); ?>
      </div>
      <br clear="all" />
      <?php else: ?>
      <div id="dr-message-error">
        <?php _e( 'Email service is not responding!', 'classifieds' ); ?>
      </div>
      <?php
    endif;
    
    endif; ?>
      <?php if( empty( $options['disable_contact_form'] ) ): ?>
      <form method="post" action="#" class="contact-user-btn action-form" id="action-form">
        <input type="submit" name="contact_user" value="<?php _e('Contact User', 'classifieds' ); ?>" onclick="dr_listings.toggle_contact_form(); return false;" />
      </form>
      <div class="clear"></div>
      <form method="post" action="#" class="standard-form base dr-contact-form" id="confirm-form">
        <?php
    	global $current_user;
    
    	$name   = ( isset( $current_user->display_name ) && '' != $current_user->display_name ) ? $current_user->display_name :
    	( ( isset( $current_user->first_name ) && '' != $current_user->first_name ) ? $current_user->first_name : '' );
    	$email  = ( isset( $current_user->user_email ) && '' != $current_user->user_email ) ? $current_user->user_email : '';
    	?>
        <div class="editfield">
          <label for="name">
            <?php _e( 'Name', 'classifieds' ); ?>
            (
            <?php _e( 'required', 'classifieds' ); ?>
            )</label>
          <input type="text" id="name" name ="name" value="<?php echo ( isset( $_POST['name'] ) ) ? $_POST['name'] : $name; ?>" />
          <p class="description">
            <?php _e( 'Enter your full name here.', 'classifieds' ); ?>
          </p>
        </div>
        <div class="editfield">
          <label for="email">
            <?php _e( 'Email', 'classifieds' ); ?>
            (
            <?php _e( 'required', 'classifieds' ); ?>
            )</label>
          <input type="text" id="email" name ="email" value="<?php echo ( isset( $_POST['email'] ) ) ? $_POST['email'] : $email; ?>" />
          <p class="description">
            <?php _e( 'Enter a valid email address here.', 'classifieds' ); ?>
          </p>
        </div>
        <div class="editfield">
          <label for="subject">
            <?php _e( 'Subject', 'classifieds' ); ?>
            (
            <?php _e( 'required', 'classifieds' ); ?>
            )</label>
          <input type="text" id="subject" name ="subject" value="<?php echo ( isset( $_POST['subject'] ) ) ? $_POST['subject'] : ''; ?>" />
          <p class="description">
            <?php _e( 'Enter the subject of your enquiry here.', 'classifieds' ); ?>
          </p>
        </div>
        <div class="editfield">
          <label for="message">
            <?php _e( 'Message', 'classifieds' ); ?>
            (
            <?php _e( 'required', 'classifieds' ); ?>
            )</label>
          <textarea id="message" name="message"><?php echo ( isset( $_POST['message'] ) ) ? $_POST['message'] : ''; ?></textarea>
          <p class="description">
            <?php _e( 'Enter the content of your enquiry here.', 'classifieds' ); ?>
          </p>
        </div>
        <div class="editfield">
          <label for="dr_random_value">
            <?php _e( 'Security image', 'classifieds' ); ?>
            (
            <?php _e( 'required', 'classifieds' ); ?>
            )</label>
          <img class="captcha" src="<?php echo admin_url('admin-ajax.php?action=dr-captcha');?>" />
          <input type="text" id="dr_random_value" name ="dr_random_value" value="" size="8" />
          <p class="description">
            <?php _e( 'Enter the characters from the image.', 'classifieds' ); ?>
          </p>
        </div>
        <div class="submit">
          <p>
            <?php wp_nonce_field( 'send_message' ); ?>
            <input type="submit" class="button confirm" value="<?php _e( 'Send', 'classifieds' ); ?>" name="contact_form_send" />
            <input type="submit" class="button cancel"  value="<?php _e( 'Cancel', 'classifieds' ); ?>" onclick="dr_listings.cancel_contact_form(); return false;" />
          </p>
        </div>
      </form>
      <?php endif; ?>
    </div>

    Am I missing something?

    Thanks,
    William

  • Ash

    Hello @William

    I hope you are doing good.

    original single-listing.php page it removes a huge chunks of my custom single-listing.php page

    Just to make sure, the original single-listing.php is from the plugin and your custom single-listing.php is from your theme? If so, then yes it won't work. The custom single-listing.php needs to be created following your page.php or single.php file. We can help you with that, but first please confirm me above.

    Have an awesome day!

    Cheers
    Ash

  • William

    Hi Ash

    The custom single-listing.php needs to be created following your page.php or single.php file.

    As you can see by my screen shot I had the page completely dialed in and scripted to my theme. I had originally planned not to use a contact form on this page and just provide an email address, but I have now changed my mind.

    I grabbed the contact form code snip-it from the original plugin file and added it to my custom single-listing.php page.

    I hope I am not confusing things....

    William

  • William

    Hi Kasia,

    I must have totally spaced and uploaded the wrong file. When I uploaded the correct file with code changes you provided it seems to be working.

    I noticed there is a contact button and the form is auto loading under it. When I click on the contact button it just refreshes the page and adds a # to the end of the url.

    If I fill out the form and submit it from the bottom button I get a message sent successfully message.

    Is there any way to have the contact form load, or event better, pop up after the "contact agent" button is clicked? Similar to the "Contact Pro" button on the WPMUDEV website*?
    *See last two screen shots in my original message in this thread.

    Thanks for all your help with this! :slight_smile:

    William

  • Kasia Swiderska

    Hello William,

    If you want a popup that shows when you click button then you can use Popup Pro plugin that Rupok suggested here https://premium.wpmudev.org/forums/topic/contact-form-in-directory-listing-questions#post-1032333
    You will not be able to use PHP custom form inside, but there are plugins like Contact Form 7, Gravity Forms where you can easily setup Contact forms and add into the Popup.

    Writing custom solution for this is bit beyond of the support scope https://premium.wpmudev.org/manuals/using-wpmu-dev/support-vs-custom-development/

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.