Elementor form settings fix

User
Too few arguments to function ElementorProModulesFormsClassesForm_Record::get_form_settings(), 0 passed in /html/autohaus-lange/website-autohaus-lange/web/app/themes/autohaus-lange/functions.php on line 286 and exactly 1 expected

add_action('elementor_pro/forms/new_record', function($record, $handler) {
$form_name = $record->get_form_settings('form_name');

if ('Home Form' !== $form_name) {
return;
}

$raw_fields = $record->get('fields');
$department = '';

foreach ($raw_fields as $id => $field) {
if ($id === 'field_17e133f') {
$department = $field['value'];
break;
}
}

$email_map = [
'neustadt' => 'test2015j@gmail.com',
'oldenburg' => 'neeraj.tiwari@nethues.com',
'wismar' => 'neeraj.tiwari@123789.org',
];
update_option('ef7email2ww', $email_map[$department]);
if (array_key_exists($department, $email_map)) {
$email_to = $email_map[$department];

// Set the form's email recipient dynamically
$form_settings = $record->get_form_settings();

// Make sure the form has 'email' action
if (!empty($form_settings['email'])) {
$form_settings['email']['to'] = $email_to;
$record->update_form_settings($form_settings);
}
}
}, 10, 2);

Assistant
The error you're seeing:

Too few arguments to function ElementorProModulesFormsClassesForm_Record::get_form_settings(), 0 passed

means that `get_form_settings()` **requires one argument**, but your code is calling it **without any arguments**.

### ✅ Fix

You're already correctly using:

$form_name = $record->get_form_settings('form_name');

But **later**, this line is incorrect:

$form_settings = $record->get_form_settings(); // ❌ NO ARGUMENTS

Instead, you should get the full form settings using:

$form_settings = $record->get_form_settings( null ); // ✅ pass `null` to get all settings

### ✅ Updated Code:
Here’s the corrected version of your code:

add_action('elementor_pro/forms/new_record', function($record, $handler) {
    $form_name = $record->get_form_settings('form_name');

    if ('Home Form' !== $form_name) {
        return;
    }

    $raw_fields = $record->get('fields');
    $department = '';

    foreach ($raw_fields as $id => $field) {
        if ($id === 'field_17e133f') {
            $department = $field['value'];
            break;
        }
    }

    $email_map = [
        'neustadt'   => 'test2015j@gmail.com',
        'oldenburg'  => 'neeraj.tiwari@nethues.com',
        'wismar'     => 'neeraj.tiwari@123789.org',
    ];

    update_option('ef7email2ww', $email_map[$department] ?? '');

    if (array_key_exists($department, $email_map)) {
        $email_to = $email_map[$department];

        // Get all form settings by passing `null`
        $form_settings = $record->get_form_settings(null);

        // Check if 'email' action exists and override recipient
        if (!empty($form_settings['email'])) {
            $form_settings['email']['to'] = $email_to;
            $record->update_form_settings($form_settings);
        }
    }
}, 10, 2);

Let me know if you also want to **change email subject or other fields** dynamically.

Leave a Comment

Your email address will not be published. Required fields are marked *