SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    treating phone numbers, cols

    I have a form the Inserts phone numbers.

    It has four fields for: (area)-XXX-XXXX - ext //field for their extension.

    Then another alternate phone number. This totals eight columns just for phone numbers.

    On another site I simply have one field for the entire phone number. Problem that i've discoverd is that many users don't know whether to hypehn, or how to include their phone extensions if they have them. So I end up having to manually edit many of these. (staying away from javascript for those who don't have it enabled)

    Isn't there a better way than to have eight fields for this (and having to echo eight fields back when the time comes)? (actually plus two more fields, for preferred times of contact for ea. phone number)

    Is there a way to Insert these four fields "(area)-XXX-XXXX-ext" all in to a single column? (don't presently have a confimation page to show user their values before Inserting but this may come)

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    San Diego, CA (USA)
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, you could have three different inputs, one for each part of the phone number. heres an example of how it can work:

    PHP Code:
    <?php
    //phoneform.php

    if (isset ($_POST['submit'])) {
         
    $part1 $_POST['area'];
         
    $part2 $_POST['first3'];
         
    $part3 $_POST['last4'];
         
    $number $part1.'-'.$part2.'-'.$part3;
         
    //here, you can put a mysql query that adds $number to the correct column
    }

    print 
    '<form action="'.$PHP_SELF.'" method="post" name="phone">
      <p>Your Phone Number (format: [area code]-[first 3 digits]-[last 4 digits)<br>
        <input name="area" type="text" size="10" maxlength="3">
        -
        <input name="first3" type="text" size="10" maxlength="3">
        -
        <input name="last4" type="text" size="10" maxlength="4">
        <br>
        <input name="submit" type="submit" id="submit" value="Submit">
      </p>
    </form>'
    ;
    ?>
    and if you ever wanted to split the phone numbers back into 3 different parts, you could do this:

    PHP Code:
    //start mysql database lookup
    $number $row['number']; //this row value is just an example
    //end mysql lookup

    list ($part1$part2$part3) = explode ('-'$number); 
    i hope i helped.


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
  •