Results 1 to 6 of 6

Thread: Email Form

  1. #1
    Join Date
    Feb 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Email Form

    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.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well[not seeing your code]:
    PHP Code:
    $tel $_POST['tel'];
    $con $_POST['body'];
    $body $con .'\n And heres there telephone #:\n'.$tel
    Jeremy | jfein.net

  3. #3
    Join Date
    Feb 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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"] .

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try it, and if it works, can you press the Thanks button under my post?
    Jeremy | jfein.net

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    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">)
    Code:
    $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.

    PHP Code:
    $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
    Code:
    <input type="text" name="fieldN" value="<?php echo $_POST['fieldN']; ?>">

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by jeffreypowers View Post
    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.
    Last edited by boogyman; 02-18-2008 at 03:47 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •