Skip Navigation

[Resolved] Do not allow space with username field with CRED user form while creating users

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

Problem:
Do not allow space with username field with CRED user form while creating users.

Solution:
You can use CRED hook cred_form_validate to validate your form.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/username-field/#post-626843

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by sahrf 6 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#626771

Tell us what you are trying to do?
In the user registration i have allowed the user to type in there username but I would like to put in a validation where there should not be any spaces. Is that possible?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

#626843

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - you can use CRED hook cred_form_validate to validate your form.

For example - add following code to your current theme's functions.php file:

add_filter('cred_form_validate','validate_space_in_login',10,2);
function validate_space_in_login($field_data, $form_data)
{
    list($fields,$errors)=$field_data;
    if ( $form_data['id'] == 99999) {
		if(strpos($fields['user_login']['value'],' ') !== false){
			 $errors['user_login']='Please enter username without space.';   
		}

    }
    return array($fields,$errors);
}

Where:
- Replace the 99999 with your original CRED form ID.

More info:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#628052

Very efficient and quick