Hi, I'm with WordPress at all. Help advice how to implement the following. There is a site on WordPress and there is a form for contact. After entering this form, the user needs to send a request to another server with this data. That is, the user entered the data and we send it to another server. I wrote a lot on Yii2, Laravel and my framework thinking does not make it clear in WordPress logic. Tell me how it can be implemented, where at least to find the files with the processing of the contact form that would add the code to send to another server

Form Code:

<form class="et_pb_contact_form clearfix" method="post" action="http://linkdnetwork.com/contact/"> <p class="et_pb_contact_field et_pb_contact_field_0 et_pb_contact_field_half" data-id="first name" data-type="input"> <label for="et_pb_contact_first name_1" class="et_pb_contact_form_label">First Name</label> <input type="text" id="et_pb_contact_first name_1" class="input" value="" name="et_pb_contact_first name_1" data-required_mark="required" data-field_type="input" data-original_id="first name" placeholder="First Name"> </p> <p class="et_pb_contact_field et_pb_contact_field_1 et_pb_contact_field_half et_pb_contact_field_last" data-id="last name" data-type="input"> <label for="et_pb_contact_last name_1" class="et_pb_contact_form_label">Last Name</label> <input type="text" id="et_pb_contact_last name_1" class="input" value="" name="et_pb_contact_last name_1" data-required_mark="required" data-field_type="input" data-original_id="last name" placeholder="Last Name"> </p> <p class="et_pb_contact_field et_pb_contact_field_2 et_pb_contact_field_last" data-id="company/organisation name" data-type="input"> <label for="et_pb_contact_company/organisation name_1" class="et_pb_contact_form_label">Company/Organisation Name</label> <input type="text" id="et_pb_contact_company/organisation name_1" class="input" value="" name="et_pb_contact_company/organisation name_1" data-required_mark="required" data-field_type="input" data-original_id="company/organisation name" placeholder="Company/Organisation Name"> </p> <p class="et_pb_contact_field et_pb_contact_field_3 et_pb_contact_field_last" data-id="website url (if applicable)" data-type="input"> <label for="et_pb_contact_website url (if applicable)_1" class="et_pb_contact_form_label">Website URL (if applicable)</label> <input type="text" id="et_pb_contact_website url (if applicable)_1" class="input" value="" name="et_pb_contact_website url (if applicable)_1" data-required_mark="required" data-field_type="input" data-original_id="website url (if applicable)" placeholder="Website URL (if applicable)"> </p> <p class="et_pb_contact_field et_pb_contact_field_4 et_pb_contact_field_half" data-id="email" data-type="email"> <label for="et_pb_contact_email_1" class="et_pb_contact_form_label">Email</label> <input type="text" id="et_pb_contact_email_1" class="input" value="" name="et_pb_contact_email_1" data-required_mark="required" data-field_type="email" data-original_id="email" placeholder="Email"> </p> <p class="et_pb_contact_field et_pb_contact_field_5 et_pb_contact_field_half et_pb_contact_field_last" data-id="phone" data-type="input"> <label for="et_pb_contact_phone_1" class="et_pb_contact_form_label">Phone</label> <input type="text" id="et_pb_contact_phone_1" class="input" value="" name="et_pb_contact_phone_1" data-required_mark="required" data-field_type="input" data-original_id="phone" placeholder="Phone"> </p> <p class="et_pb_contact_field et_pb_contact_field_6 et_pb_contact_field_last" data-id="preferred method of contact" data-type="input"> <label for="et_pb_contact_preferred method of contact_1" class="et_pb_contact_form_label">Preferred Method of Contact</label> <input type="text" id="et_pb_contact_preferred method of contact_1" class="input" value="" name="et_pb_contact_preferred method of contact_1" data-required_mark="required" data-field_type="input" data-original_id="preferred method of contact" placeholder="Preferred Method of Contact"> </p> <input type="hidden" value="et_contact_proccess" name="et_pb_contactform_submit_0"> <input type="text" value="" name="et_pb_contactform_validate_0" class="et_pb_contactform_validate_field"> <div class="et_contact_bottom_container"> <button type="submit" class="et_pb_contact_submit et_pb_button">Submit</button> </div> <input type="hidden" id="_wpnonce-et-pb-contact-form-submitted" name="_wpnonce-et-pb-contact-form-submitted" value="3ad4ba832a"><input type="hidden" name="_wp_http_referer" value="/contact/"> </form> 

  • The form has an action tag, it points to the form processing file. Nothing new. In this file, you must accept the form fields and send them by wp_remote_post() - KAGG Design
  • @KAGG Design hmm, in contact but in the wp_content file ...> there is no contact file in the theme folder - Mike Kaharlykskiy
  • Show the code .... - KAGG Design
  • @KAGGDesign code of what? Action forms, I looked through the inspector in general - Mike Kaharlykskiy
  • Html code show. What form do you have? Custom or from the plugin? Which one - KAGG Design

1 answer 1

The form you have on the Divi theme, points to the very page where it is posted. After submitting the form, the page is updated as usual. When a form element is generated, it is processed if the fields in $_POST . Processing is done in wp-content/themes/Divi/includes/builder/main-modules.php , in ET_Builder_Module_Contact_Form->shortcode_callback() .

No hooks and filters for additional processing of the form, unfortunately, the developers Divi did not provide.

What can be done? Create a child theme from Divi, add the following code to the functions.php of the child theme:

 function process_contact_form() { // номер вашей контактной формы // (у вас на странице - 0, судя по id="et_pb_contact_form_0") $et_pb_contact_form_num = 0; $nonce_result = isset( $_POST['_wpnonce-et-pb-contact-form-submitted'] ) && wp_verify_nonce( $_POST['_wpnonce-et-pb-contact-form-submitted'], 'et-pb-contact-form-submit' ) ? true : false; // check that the form was submitted and et_pb_contactform_validate field is empty to protect from spam if ( $nonce_result && isset( $_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num] ) && empty( $_POST['et_pb_contactform_validate_' . $et_pb_contact_form_num] ) ) { // обработка формы и отправка запроса по wp_remote_post() } } add_action( 'init', 'process_contact_form' ); 

This code on the init event (WordPress initialization) checks if there is a nonce , if there is an element in $_POST indicating that the mail has been sent, and does your data processing $_POST . Check out the code in ET_Builder_Module_Contact_Form->shortcode_callback() for how to clean up $_POST elements.

  • Thanks already close to the answer! I created a child theme, but I started to display some styles incorrectly - did as I did in the instructions - added the style.css file and made an import, but some styles still didn't load - maybe tell me where to look or what to fix? Thanks for the function - added functions.php and the request flew successfully :) - Mike Kaharlykskiy
  • Ask another question about the child theme - KAGG Design
  • Created a topic - Mike Kaharlykskiy
  • Updated a topic - Maybe this will help you - Mike Kaharlykskiy