WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / Technical how to | Custom Code Required / Technical how to : Agent contact form explained

Technical how to : Agent contact form explained

6052 views 0

The agent contact form that is present in property page (at the bottom or on sidebar) and in agent page can be found in the following file:

wpresidence/templates/agent_contact.php

Here you can find the HTML code and can change labels or add extra details.

The email sending is happening via ajax.

This means that the code is located in both JavaScript files and php files

Javascript

The email sending is triggered when the send button is pushed. In this case the button has the id agent_submit and the click event is “happening” in
wpresidence-new/js/ajaxcalls.js around line 1717

$('.agent_submit_class').on( 'click', function(event) {
var contact_name, contact_email, contact_phone, contact_coment, agent_email, property_id, nonce, ajaxurl;
contact_name = $('#agent_contact_name').val();
contact_email = $('#agent_user_email').val();
contact_phone = $('#agent_phone').val();
contact_coment = $('#agent_comment').val();
agent_email = $('#agent_email').val();
property_id = $('#agent_property_id').val();
nonce = $('#agent_property_ajax_nonce').val();

*** If you want to add extra fields in the form you would need to “read” those details from the new input elements and send them using .ajax instruction to the php function wpestate_ajax_agent_contact_form().

In the javascript function the forms filled by the user are read

for ex : contact_name = $('#agent_contact_name').val();

and after that sent to the php function
'action' : 'wpestate_ajax_agent_contact_form',
'name' : contact_name,

In case of success ( the transport of data from javscript to php is a success) we clear all the forms and display the message
success: function (data) {
// This outputs the result of the ajax request

if (data.sent) {
$(‘#agent_contact_name’).val(”);
$(‘#agent_user_email’).val(”);
$(‘#agent_phone’).val(”);
$(‘#agent_comment’).val(”);
}
$(‘#alert-agent-contact’).empty().append(data.response);

 

The php function wpestate_ajax_agent_contact_form is in theme plugin : wpresidence-core in plugins/wpresidence-core/misc/emailfunctions.php at line 9

In there the data sent via javacript is retrived as $_POST variables . For ex the contact name , was sent as “name” (see js code) and now is used as $_POST[‘name’];

After all the data received is checked we compose the message at line 2778 and the email is sent via this line
$mail = @wp_mail($receiver_email, $subject, $message, $headers);

If you make use of the duplicate email feature : “theme options -> social & contact -> Send all contact emails to” the code that send the second email is

if($duplicate_email_adr!=''){
$message = $message.' '.__('Message was also sent to ','wpestate').$receiver_email;
wp_mail($duplicate_email_adr, $subject, $message, $headers);
}

If you need to know more about how Ajax is Working with WordPress you can look over this tutorial : https://premium.wpmudev.org/blog/using-ajax-with-wordpress/

Technical how to | Custom Code Required

Related Articles

  • Technical: Change the Schedule Tour Email Text and the Form Default Message
  • Property list filter customization
  • Technical – How to Change the Minimum Image Dimensions for Property Uploads in WPResidence
  • Introduction to WPResidence Header Customization

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language Third Party Plugins
  • 6Other Third party Plugins
  • 19Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 36Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 6Translations & Languages
  • 16WPBakery Shortcodes
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio
  • 50WPResidence Translate Plugin

Join Us On

Powered by WP Estate - All Rights Reserved
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API