0

Привет, я с вордпресом вообще на Вы. Помогите советом как можно реализовать следующее. Есть сайт на вордпрес и там есть форма для контакта. Нужно после ввода этой формы юзером отправить запрос на другой сервер с этими данными. То есть пользователь ввёл данные и мы их отправляем на другой сервер. Я писал много на Yii2, Laravel и моё фреймворковское мышление не даёт понять логику в вордпресе. Подскажите как это можно реализовать, где хотя бы найти файлы с процессом обработки формы контактов что бы добавить туда код для отправки на другой сервер

Код формы:

<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>

7
  • В форме есть тег action, он указывает на файл обработки формы. Ничего нового. В этом файле надо принять поля формы и отправить их по wp_remote_post() 4 апр 2018 в 18:50
  • @KAGG Design хм, в екшине contact но в файле wp_content ... > в папке темы нету файла contact 4 апр 2018 в 20:03
  • Покажите код.... 4 апр 2018 в 20:18
  • @KAGGDesign код чего? Action формы я вообще через инспектор посмотрел 4 апр 2018 в 21:33
  • Html код покажите. Что за форма у вас? Кастомная или из плагина? Какого? 4 апр 2018 в 21:41

1 ответ 1

0

Форма у вас от темы Divi, указывает на саму страницу, где она размещена. После отправки формы, происходит обновление страницы, как обычно. При генерации элемента формы происходит её обработка, если установлены поля в $_POST. Обработка проводится в wp-content/themes/Divi/includes/builder/main-modules.php, в ET_Builder_Module_Contact_Form->shortcode_callback().

Никаких хуков и фильтров для дополнительной обработки формы, к сожалению, разработчики Divi не предусмотрели.

Что можно сделать? Создать дочернюю тему от Divi, в functions.php дочерней темы добавить такой код:

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' );

Этот код по событию init (инициализация WordPress) проверяет, есть ли nonce, есть ли элемент в $_POST, свидетельствующий об отправке почты, и делает вашу обработку данных $_POST. Посмотрите код в ET_Builder_Module_Contact_Form->shortcode_callback(), на предмет того, как производится очистка элементов $_POST.

4
  • Спасибо уже близко к ответу! Я создал дочерную тему но у меня некоторые стили стали некорректно отображаться - сделал как в инструкции - добавил файл style.css и сделал import, но некоторые стили все равно не загрузились - может быть подскажите куда посмотреть или что исправить? По функции спасибо - добавил functions.php и запрос успешно полетел :) 5 апр 2018 в 13:28
  • Задайте другой вопрос касательно дочерней темы 5 апр 2018 в 13:42
  • Создал тему 5 апр 2018 в 14:41
  • Обновил тему - Возможно Вам это поможет 5 апр 2018 в 16:46

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.