WP Residence Help WP Residence Help

  • WpEstate
  • How to Build Your Website
  • 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

5711 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 – How to Change the Minimum Image Dimensions for Property Uploads in WPResidence
  • Introduction to WPResidence Header Customization
  • Understanding WPResidence Header Types: An Overview
  • Customizing the WPResidence Logo Display

WP Residence Documentation

  • 1. General
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 2. Installation
  • 3. Installation FAQ
  • 4. Advanced Search
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 5. Agent, Agency & Developers
  • 6. Property Page
  • 7. Properties List
  • 8. Property Taxonomies
  • WpResidence Elementor Studio
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • Theme Options
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • Translation
  • FAQ
  • Pages
  • Header
  • Footer
  • Google or Open Street Maps
  • Payment Options
  • Plugins
    • Included Plugins
    • Third Party Plugins – IDX Compatibility
    • Third Party Plugins – Multi Languages
    • Third party Plugins – Other
  • Technical
    • Technical how to | Custom Code Required
    • Technical: Child Theme

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • How to Build Your Website
  • Video Tutorials
  • Client Support
  • API