Home › Forums › Backend Issues (wp-admin) › Issue with getting data from Elementor form
Got an issue with my code, See Below
add_action( 'elementor_pro/forms/new_record', 'thewpchannel_elementor_form_create_new_user' , 10, 2 );
function thewpchannel_elementor_form_create_new_user($record,$ajax_handler)
{
$form_name = $record->get_form_settings('form_name');
//Check that the form is the "create new user form" if not - stop and return;
if ('Create New User' !== $form_name) {
return;
}
$form_data = $record->get_formatted_data();
$username=$form_data['Username']; //Get the value of the input with the label "User Name"
$password = $form_data['Password']; //Get the value of the input with the label "Password"
$email=$form_data['Email']; //Get the value of the input with the label "Email"
$user = wp_create_user($username,$password,$email); // Create a new user, on success return the user_id no failure return an error object
$user_role = new WP_User($user);
$user_role->set_role('unimproved_user');
if (is_wp_error($user)){ // if there was an error creating a new user
$ajax_handler->add_error_message("Failed to create new user: ".$user->get_error_message()); //add the message
$ajax_handler->is_success = false;
return;
}
$last_name=$form_data["Last Name"]; //Get the value of the input with the label "Last Name"
$company_name=$form_data['acf']['Company Name']; // Get Company Data from form
update_field( 'field_6182b31388dbe', $company_name, 'user_'.$user );
wp_update_user(array("ID"=>$user,"first_name"=>$company_name,"last_name"=>$last_name)); // Update the user with the first name and last name
}
Now the $company_name field isn’t working for me, I’m unable to capture anything from the form. The form is built with basic Elementor and ACF. I’ve tried the method you see, I’ve tried doing $form_data[‘field_6182b31388dbe’] and a few more variations.
Any help would be greatly appreciated
Sam
HI @samnymr
I’m not at all familiar with elementor, however, can you see if the below works:
<?php
add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) {
//make sure its our form
$form_name = $record->get_form_settings( 'form_name' );
if ( 'Create New User' !== $form_name ) {
return;
}
$raw_fields = $record->get( 'fields' );
$fields = [];
$admin_email = $no_exists_value = get_option( 'admin_email' );
$to = $admin_email;
$subject = 'Test form submission data';
$message = 'Form data';
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
$message .= $field['value'];
}
$headers = 'From: My Name <[email protected]>' . "\r\n";
wp_mail( $to, $subject, $message, $headers );
}, 10, 2);
The idea being on form submission, it should email the site admin address a list of form data.
Check whether the company name is present.
If not, the data isn’t reaching the submission.
If it is, you can then look to see which part may then be failing.
Hiya!
User is defined when its created 🙂
The issue seems to be around the get formatted data option
I’ll try your method of emailing it to myself and see if that helps 🙂
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.