Hey Everyone. When a user signs up, their Phone Number is very important in my DB, so I'd like to ensure its submitted properly. What is the correct way to customize the code so I have three fields on the signup form that I can then validate for correct US lengths [3] [3] [4]. If correct, I'd then concatonate the number into 555-555-5555. Also, I'm going to need some additional fields in the member table for some things that the user will not see. Will adding them with phpMyAdmin create an issue later with upgrading. Or will it mess up aMember if I do so? Thanks Dave
amember/site.inc.php PHP: <?phpfunction vsf(&$vars){ $err = array(); $phone = preg_replace('/\D+/', '', $vars['phone']); if (strlen($phone) != 10) { $err[] = "Phone number must contain 10 digits"; return $err; } $vars['phone'] = substr($phone, 0, 3) . '-' . substr($phone, 3, 3) . '-' . substr($phone, 6, 4);}setup_plugin_hook('validate_signup_form', 'vsf');?>
Thanks Alex. I understand what you're suggesting. I was hoping however to split the signup form up into 3 fields so they tab through the 3 fields: [ ]-[ ]-[ ] Those 3 fields (say 'phone1', 'phone2', and 'phone3') are concatenated to be ###-###-#### and entered into 'phone' in the DB. Doing this with "additional fields" would create 3 fields in the DB. I would not want to do that. Should I just hard code this? If so, where would be the proper place to put this. Thanks for the help.
If you provide FTP info and aMember CP login info, we will make this change for you. It is too long to explain here.
Error in storage Alex - When i placed your code in a site.inc file, the result was that the database only stores the first three digits in the phone field. Is this due to that field being an int field? How can this be fixed? (i like displaying the number broken up...easy for my customer to read) Thanks
Hey, I finally got around to resolving this by using one field as alex suggested. It worked perfectly stripping out any unwanted characters and inserting "-" to format the number. It does need to be set to varchar but thats fine. Works great. Thanks again alex.
Where do you change the phone field to varchar? __________________________________________ Never mind, forgot that phone was a custom field.
in amember pro, you must have created the field using "add fields" in the admin. you can change the type to varchar there.
I have need to support a phone field and a date field on my aMember Signup page. What is the best way to make sure they are validated? In this thread it seems like Alex has some custom code that handles the validation?
I need to add a phone field to the sign up form also. I want to be sure I get this straight so it works 1.) put the above .php code into my site.inc page 2.) then add a field in the amember admin - I have questions about these settings: ==> what is the display type - text or text area? ==> input fields - the size of input field has a default of "20" what should be there? ==> default value for the field - what should this be? ==> validation function - what should this be? Thanks! Claudia
Display type should be set to text Size - leave as is default value leave empty validation function - required
Thanx! Alexander, I did the phone field without the three sections and this worked seemlessly first time round! (for a change ) Claudia
Hi Alex, I added your PHP to my site.inc.php file, changing the variable name to phone_office to match the one I created in the admin custom fields. Code: function vsf(&$vars){ $err = array(); $phone = preg_replace('/\D+/', '', $vars['phone_office']); if (strlen($phone) != 10) { $err[] = "Phone number must contain 10 digits"; return $err; } $vars['phone'] = substr($phone, 0, 3) . '-' . substr($phone, 3, 3) . '-' . substr($phone, 6, 4); } setup_plugin_hook('validate_signup_form', 'vsf'); It's not working though, the field is required but it's not validating. Can you help? Here's the form: http://www.cvsinc.net/amember/signup.php I also have a phone_cell field that I need to do validation on too.
My apologies - it actually is working fine. Code: /* Validation for phone_office field*/ function vsf(&$vars){ $err = array(); $phone = preg_replace('/\D+/', '', $vars['phone_office']); if (strlen($phone) != 10) { $err[] = "Office number must contain 10 digits"; return $err; } $vars['phone_office'] = substr($phone, 0, 3) . '-' . substr($phone, 3, 3) . '-' . substr($phone, 6, 4); } setup_plugin_hook('validate_signup_form', 'vsf'); /* Validation for phone_cell field*/ function vsfcell(&$vars){ $err = array(); $phone_cell = preg_replace('/\D+/', '', $vars['phone_cell']); if (strlen($phone_cell) != 10) { $err[] = "Cell phone number must contain 10 digits"; return $err; } $vars['phone_cell'] = substr($phone_cell, 0, 3) . '-' . substr($phone_cell, 3, 3) . '-' . substr($phone_cell, 6, 4); } setup_plugin_hook('validate_signup_form', 'vsfcell');