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/