Skip Navigation

[Resolved] converting user_email field from a register form to lowercase

This thread is resolved. Here is a description of the problem and solution.

Problem:
Tell us what you are trying to do?
ensure a user_email field from a register form is saved as lowercase

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

Is there a similar example that we can see?
trying this:

add_action('cred_before_save_data', 'my_before_save_data_action',10,1);
function my_before_save_data_action($form_data)
{
// if a specific form
// 61544 = register form v2

if ($form_data['id']== 61544)
{
if (isset($_POST['user_email']))
{

$lowercaseemail = strtolower($_POST['user_email']);

$_POST['user_email'] = $lowercaseemail;
}
}
}

Solution:
The approach you took is correct, I believe the issue might be with the missing 'wpcf' prefix in the field selection.

Can you please try the following code to see if it achieves what you need?

add_action("cred_before_save_data", "my_before_save_data_action", 10, 1);
function my_before_save_data_action($form_data)
{
    // if a specific form
    // 61544 = register form v2
 
    if ($form_data["id"] == 61544) {
        if (isset($_POST["user_email"])) {
            $lowercaseemail = strtolower($_POST["user_email"]);
 
            $_POST["wpcf-user_email"] = $lowercaseemail;
        }
    }
}

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 1 reply, has 2 voices.

Last updated by Mateus Getulio 4 months, 1 week ago.

Assisted by: Mateus Getulio.

Author
Posts
#2675199

Tell us what you are trying to do?
ensure a user_email field from a register form is saved as lowercase

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

Is there a similar example that we can see?
trying this:

add_action('cred_before_save_data', 'my_before_save_data_action',10,1);
function my_before_save_data_action($form_data)
{
// if a specific form
// 61544 = register form v2

if ($form_data['id']== 61544)
{
if (isset($_POST['user_email']))
{

$lowercaseemail = strtolower($_POST['user_email']);

$_POST['user_email'] = $lowercaseemail;
}
}
}

What is the link to your site?

#2675285

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

The approach you took is correct, I believe the issue might be with the missing 'wpcf' prefix in the field selection.

Can you please try the following code to see if it achieves what you need?

add_action("cred_before_save_data", "my_before_save_data_action", 10, 1);
function my_before_save_data_action($form_data)
{
    // if a specific form
    // 61544 = register form v2

    if ($form_data["id"] == 61544) {
        if (isset($_POST["user_email"])) {
            $lowercaseemail = strtolower($_POST["user_email"]);

            $_POST["wpcf-user_email"] = $lowercaseemail;
        }
    }
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.