-
☆ A M B ☆
- 894 Posts
Hey fellow MODxers got a question for ya, does anyone know how to validate a phone number form field in MODx using FormIt?
I also need to know if it supports multiple emails, i tried separating emails by , and ; and it would give me the success message but I never received any emails.
Thanks for your help.
-
☆ A M B ☆
- 3,141 Posts
Hooks!
To validate your phone number, try a custom hook with something like this:
# Get the phone number from somewhere
$phone = ...;
# Strip out non-digits
$phone = preg_replace('/\D/', '', $phone);
# Ensure it's well-formed
if (! preg_match('/^0\d{9}$/', $phone)) {
# Phone number is not well-formed... do some errory thing
return false;
}
# Passed the test
return true;
The email hook support comma separated multiple emails in &emailTo.
(From Google, there’s plenty other scripts to find)
-
☆ A M B ☆
- 3,141 Posts
Forget my earlier comment - a custom validator is probably the preferred method (though using a somewhat similar approach using snippets).
-
☆ A M B ☆
- 894 Posts
Well this turned out being more complicated than I imagined (for me at least) what I ended up doing was using 3 input text to create the phone number, I set a maxlength to each and use jquery autotab plugin so when the user reaches the maxlength of the input field it auto focuses on the next input.
Now my problem is how can I have formit display just one error message if one of the three fields is left blank?
Special thanks to Mark, Patrick R. and @Salscode for their help and suggestions regarding this matter over skype.
-
☆ A M B ☆
- 2,213 Posts
Only require 1 of the 3 fields and use inline JS validation to get the other two