-
Hi
How do you insert phone number validation?
I did a search on the forum for “validation” and it returned no entries.
You need to add a custom ajax validation callback. see ajax.php case ‘username_exists’: for example, you can do similar tests if you apply ajax callback to a field. This is custom coding also.
Again…validation of a field should be easy and not require custom coding.
What solution provides unlimited fields validation where you can extract very specific validation or php tests etc.. or comparison.. name the solution please
Google any form plugin in WordPress. Even the basic ones have validation options for a phone number. Most have a regex validation field which can be customised almost to any field. 🙂
Ok I talk about that regex validation, if you know just little php and copy/paste code you can apply any regex validation and return error if it does not match certain conditions? need a simple example? open functions/ajax.php ok?
now find this line:
case ‘username_exists’:
if (username_exists($input_value)){
$output[‘error’] = __(‘Username already taken.’,’userpro’);
} else if ( !preg_match(“/^[A-Za-z0-9_]+$/”, $input_value) ) {
$output[‘error’] = __(‘Illegal characters are not allowed in username.’,’userpro’);
}
break;See? You simply test the $input_value against if username exists.. and then test it for illegal characters regex.. now you can add ajax callback to any field and append this code in ajax.php and the test will run on each field, in real time-ajax!
@Ahmed – will this code get lost on a plugin update if I add it to ajax.php??
Could I request you to add a regex option to all fields for validation?
Lab41 you are wrong. You want regex validation on fields, other people may want ajax validation (which is already done) lets say to check if entered good valid post code of specific country and so on. So PHP (ajax) callbacks are better then stone age regex. Of course we don’t mind to get both 🙂
Also this is users plugin not fields plugin so comparing to google forms plugin is funny.
But this question: “will this code get lost on a plugin update if I add it to ajax.php??” is very good. Anyway any noob developer can just add line to ajax.php file to include custom php file in it. So after upgrade -you will only have to put 1 line of code to ajax.php, ofcourse Ahmed could add that line from now on to include some static c_ajax.php if that file exists. So no need to add it after upgrade.
@thomas – I don’t mind which type or regex is added. But advising to add a line of code that get’s lost on updates is not good. Since it gets impossible to track what plugins have what lines all added across many sites. Makes it a nightmare.
Surely other users require regex so it should be an option….??? Unless this is not a generally required feature, but then again, why do most form plugins offer regex?
I agree that changing plugin files is not good option to implement custom work.
Also i agree that REGEX validation would be nice. Which i think Ahmed will do, cause i think many people can see that Ahmed always implements good stuff if people wants it. ( i suggest you to add this to request forum topic, so people can vote for it) But you saying about regex like this is common thing and it already have to be done. As i said previously-yes if this would be some custom forms plugin (btw most of them don’t have this function). But this is user management plugin which also have ability to custom fields.Anyways i think Ahmed will do this, and he already even got field [Help text] so he can use that field for error display if validation fails 🙂 So left the JavaScript part 😀
The ajax callback has a built-in mechanism to return error if the input does not match certain check. Did you see above example?
I can take $input_value and test it against a specific regex, or check if that user already exists.. no limits 🙂
basically if you edit your ajax.php just keep a copy of your updated ajax.php that’s all 🙂
Problem comes in when you have many themes, many plugins and many customisations. It gets impossible to track all the changes through updates. Then you have a different dev and they forget and things break. That’s why it’s better if it’s a plugin setting rather than a customisation.
You can’t add custom php code in plugin settings. 🙂
In the meantime, just backup your modified ajax.php file
Ahmed but i guess it’s not hard for u to add one line to ajax.php to include some static php file if it exists. so people name their php file with validation rules the same as in your ajax.php and they can update plugin with problems free 🙂
Just like WP uses functions.php file.
You must be logged in to reply to this topic.