Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorjustjack
    • CommentTimeDec 6th 2006 edited
     permalink
    Can someone explain or direct how to insert a phone number in database as 555 555 555 all together once a form is processed. Don't know how to do this. Working on it a while. Let me know if you would like to see the code. I will direct to page. To save time, www.loadedmoment.com/formwork.html
    • CommentAuthordavist11
    • CommentTimeDec 6th 2006 edited
     permalink
    You can just use str_replace to get rid of any spaces in the phone number:
    http://us2.php.net/str_replace

    so just say $phone1 = str_replace(" ", "", $_POST[phone1]) instead of $phone1 = "$_POST[phone1]"
    • CommentAuthorMatt
    • CommentTimeDec 6th 2006
     permalink
    $phone = intval($_POST['phonePart1']) . intval($_POST['phonePart2']) . intval($_POST['phonePart3']);
    • CommentAuthorjustjack
    • CommentTimeDec 6th 2006
     permalink

    Matt,

    I'm assuming this code goes in the php processing form. If so, how do i write the output "echo" for the client to see what their submission was. I just tried putting in this line of code and when i ran it it generated "0000" for the number.
    And finally, in a database do I need 3 seperate spots for this or just one long enough for the entire number.

    $phone = intval($_POST['phone1']) . intval($_POST['phone2']) . intval($_POST['phone3']); (Is this still correct if this is how I have my code set. I took the "parts" out

    echo "



    Phone: $phone1. $phone2, $phone3


  1.  permalink
    you could just output $phone.

    If you insert the single $phone variable into the database, you'd just need one column in the table for phone number. If you use $phone1,$phone2,$phone3 you'll need 3 columns.
    • CommentAuthorjustjack
    • CommentTimeDec 12th 2006
     permalink
    Hey Marcus or anyone can you be more specific. Tried that and I still only get the last 4 digits to process. I have updated the page at www.loadedmoment.com/formwork.html
    • CommentAuthordhayes
    • CommentTimeDec 12th 2006 edited
     permalink
    change:

    $phone = "$_POST[phone]";

    to:

    $phone = implode('',$_POST['phone']);


    -Devin
    • CommentAuthordhayes
    • CommentTimeDec 12th 2006
     permalink
    thought I'd drop back and elaborate a little more. when you add brackets to an input name, you create an array:

    <input type="text" name="phone[]" value="asdasd" />

    submitting this would result in an array that looked like:

    Array ( [phone] => Array ( [0] => asdasd ))

    ..supposing you have mulitple inputs for the phone number (which there is):

    <input type="text" name="phone[areacode]" value="415" />
    <input type="text" name="phone[prefix]" value="838" />
    <input type="text" name="phone[suffix]" value="1212" />

    on submit, you would get:

    Array ( [phone] => Array ( [areacode] => 415 [prefix] => 838 [suffix] => 1212 ))

    so now that you've got your keys structured, you can access then more easily like:

    echo $_POST['phone']['areacode'];
    // results in: 415

    implode takes an array and builds a string out of it, so imploding the array "phone" ($_POST['phone']):

    echo implode('',$_POST['phone']);
    // results in: 5188381212


    ..hope it helps.
Add your comments
    Username Password
  • Format comments as (Help)