
Originally Posted by
jeffreypowers
Sorry about the code. I think I understand what you gave me but just to be sure.
SOURCE CODE:
$message = "Name: " . $_POST["namefirst"] .
"\r\n Address: ". $_POST["address"] .
"\r\n Email Address: ". $_POST["email"] .
"\r\n Phone Number: ". $_POST["phone1"] .
this looks more like you are trying to write out an email? then concatenate phone variable fields.
The only problem with your code above is the extra dot at the end, and you need to end your php line with a semi-colon
Code:
$message = "Name: " . $_POST["namefirst"] .
"\r\n Address: ". $_POST["address"] .
"\r\n Email Address: ". $_POST["email"] .
"\r\n Phone Number: ". $_POST["phone1"];
Edit: Added below
okay so you are trying to format the phone.... You do not know how the user is going to enter the phone, and even though you are giving them 3 fields, they still could attempt to enter in non-digit characters...
so to format the phone you can do it one of 2 ways..
PHP Code:
$message = "Name: " . $_POST["namefirst"] .
"\r\n Address: ". $_POST["address"] .
"\r\n Email Address: ". $_POST["email"];
$message .= "Phone: ". preg_replace('/[^\d]/','',$_POST['phone1']) .'-'. preg_replace('/[^\d]/','',$_POST['phone2']) .'-'.preg_replace('/[^\d]/','',$_POST['phone3']);
which would put it in the format
ddd-ddd-dddd
provided the user entered in 3 character the first field, 3 the second and 4 the third, which is the standard USA telephone with area code. That code above would actually print any number of digits between each of the dashes because you are not checking for length. so if you do not perform any other sanitation that would allow for the user to enter in a telephone number like
111111-2-333 or 111111111-- or -222222-3333
etcetc....
But beyond that you need to look at an extension? because if the user is on telephone network, he/she might have an extension. That is something to bring up with your client. are you going to have a fourth field for the extension? are you going to have them just include it into the third field? My thoughts are that if you are separating out everything else, you should separate out the extension too.
Bookmarks