CRED plugin allows you to build forms for front-end user registration and editing. These forms can include user fields and display them with your HTML styling. They also support input validation and automatic email notifications.
When you ask for help or report issues, make sure to tell us the structure and the settings of your form.
The customer noticed that users were able to have multiple photos attached to their profiles in the WordPress Admin, even though only one photo should be allowed. He wanted to ensure that if a user removes their profile photo and resubmits the form, the photo is permanently deleted. Additionally, if a user chooses a new photo, it should replace the existing one.
Solution:
We explained that Toolset Forms does not natively support this feature but provided a workaround using custom code:
1- Use the cred_save_data action hook to trigger a PHP function when a user submits the post form.
2- In the PHP function:
• Retrieve images attached to the current post using get_attached_media.
• Access images stored in the custom repeating image field using get_post_meta.
• Compare these sets of images to identify and remove unused files using wp_delete_attachment.
Problem:
The customer wants to modify the labels of the login form so that users can log in with their email only, not their username. They can add the login form via shortcode but need to customize the form labels. Solution:
We informed the customer that customizing the login form labels requires adding custom code to the theme/child theme's function.php file. We initially provided the following code snippet:
add_filter('gettext', 'user_label_change', 20, 3);
function user_label_change($translated_text, $text, $domain) {
if ($text === 'Username or Email' && $domain == 'default') {
$translated_text = 'Email';
}
return $translated_text;
}
The customer later managed to achieve their goal with a different function:
add_filter('gettext', 'register_text');
function register_text($translating) {
$translated = str_ireplace('Username or Email', 'Your Custom Text', $translating);
return $translated;
}
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;
}
}
}