how can I have it so that when the form submits it removes all spaces in a username or doesn't let spaces be imputed for a username?
how can I have it so that when the form submits it removes all spaces in a username or doesn't let spaces be imputed for a username?
Are you using the User Registration Add-on? If so, the username there is already validated to be consistent with WordPress guidelines for usernames:
The username can only contain alphanumeric characters (A-Z, 0-9), underscores and dashes
If you're using another type of field and not using the User Registration Add-on, then you will either need to check for valid names (let the visitor know what they entered is not valid) or just modify their submission to remove the spaces.
I would suggest not allowing the spaces in the field. Please post more information about your use so we can help you with the validation. Thank you.
Hi, I figured I should just post here instead of a new thread. Anyways, here's my situation:
I'm using GF plus the user registration add-on to handle user registration for my site. However, I noticed that I'm able to create usernames with spaces. I'm also able to register 1 character long usernames.
It appears I've got everything mapped and working properly, however I really do not want to let users register with spaces and short usernames. Any idea on what's going on/how to fix?
Many thanks!
See if this helps you out:
http://www.gravityhelp.com/documentation/page/Gform_username
Rob,
Thanks for the response, however I'm still not quite sure how to write this in.
Per Chris' response above, it seems like this is supposed to be a built in function of the User Registration add-on. Am I misinterpreting what he's saying?
All I really want to accomplish is a username that fits Wordpress's guidelines (A-Z, 0-9, underscores and dashes) and more than 5 characters long. Is this something that can be easily accomplished? I am using a field for the username, so I don't need to combine fields or randomize numbers after it (I am only allowing unique entries).
Thanks again!
In the future, please go ahead and post a new thread in the support forum when you have a question or issue rather than replying to an existing thread.
The guidelines Chris posted above are the WordPress guidelines for usernames.
HOWEVER even though spaces aren't listed in the list of allowed characters that Chris listed above, WordPress DOES in fact allow usernames to contain spaces in them.
WordPress also allows usernames that are only 1 character in length.
This is why the Username validation for the User Registration Add-On allows both 1 character usernames and usernames that contain spaces to be used. WordPress allows it and therefore it isn't triggering any kind of validation issue.
In this situation WordPress, Gravity Forms and the User Registration Add-On are behaving correctly and as designed. The usernames that the User Registration Add-On allows already fit and meet WordPress guidelines.
If you don't like this default behavior, you can certainly customize how it works to suit your needs. You would need to implement your own custom validation using the gform_validation hook that checks both the length of the input as well as for the presence of spaces in the input and trigger a validation error if necessary.
You can find a tutorial on how to use the gform_validation hook to implement custom validation here:
http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook
ALSO you mentioned that you are only allowing unique entries, i'm assuming you mean the "No Duplicates" rule is enabled on the field you are using for the Username on your form. If so, there is no need to enable the "No Duplicates" in this situation. The User Registration Add-On is going to handle validation of the username field and isn't going to allow duplicates to be used. Therefore there is no need for you to enable the "No Duplicates" option on that field.