View Full Version : Email Form
jeffreypowers
02-18-2008, 03:06 PM
I have a client with php email form. They want the customer phone number in 3 field boxs. How do I make it so the numbers get stringed together in the email form. Thanks for any help.
Well[not seeing your code]:
$tel = $_POST['tel'];
$con = $_POST['body'];
$body = $con .'\n And heres there telephone #:\n'.$tel;
jeffreypowers
02-18-2008, 03:25 PM
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"] .
Try it, and if it works, can you press the Thanks button under my post?
boogyman
02-18-2008, 03:30 PM
are you talking about concatenating them to process or are you talking about concatenating the 3 fields to display?
for processing ($_POST or $_GET) depending on which method your form is using (<form method="post"> or <form method="get">)
$var = $_POST['field1'] . $_POST['field2'] . $_POST['field3'];
that would concatenate (string together) the 3 fields. If you would like to format them a certain way you would need to use some type of additional processing... usually, you just want to strip anything that isnt a digit first, then insert how you would like it processed.
$var = preg_replace('/[^\d]/','',$var);
would replace any non-digit character with nothing, thus saving the string as just digits, with no maximum or minimum length.
for output
<input type="text" name="fieldN" value="<?php echo $_POST['fieldN']; ?>">
boogyman
02-18-2008, 03:33 PM
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
$message = "Name: " . $_POST["namefirst"] .
"\r\n Address: ". $_POST["address"] .
"\r\n Email Address: ". $_POST["email"] .
"\r\n Phone Number: ". $_POST["phone1"];
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..
$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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.