TomBerry
TomBerry

Reputation: 115

Hook into form submit of Elementor pro form widget

I have created a form with the Elementor form widget and it should be a user registration form. Now I want to get the form input fields and add the user to the database. How can I get the form fields? And the sending of the e-mail (which the Elementor form widget does by default) has to be cancelled. I can cancel it via exit after the execution of my custom code (insert user to db) so that the Elementor ajax call doesn't send the e-mail.
There are some hooks in the widget (f.e. "elementor_pro/forms/form_submitted" and some others) but I would like to know the appropriate way to do this.

Do you have some idea? Please let me know.

Thanks a lot!

Upvotes: 3

Views: 18234

Answers (1)

Nic Bug
Nic Bug

Reputation: 391

From the elementor documentation it should lead you to the right direction?! You can access the values with $records->get('fields')

// A send custom WebHook
add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) {
    //make sure its our form
    $form_name = $record->get_form_settings( 'form_name' );

    // Replace MY_FORM_NAME with the name you gave your form
    if ( 'MY_FORM_NAME' !== $form_name ) {
        return;
    }

    $raw_fields = $record->get( 'fields' );
    $fields = [];
    foreach ( $raw_fields as $id => $field ) {
        $fields[ $id ] = $field['value'];
    }

    wp_remote_post( 'HTTP://YOUR_WEBHOOK_URL', [
        'body' => $fields,
    ]);
}, 10, 2 );

read more here https://developers.elementor.com/docs/hooks/forms/#form-new-record

Upvotes: 8

Related Questions