Collecting form data with PHP

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Collecting form data with PHP

    I have a basic form I made to learn how to get the results emailed to me on
    submission. This is the form: <form
    action='http://www.mywebsiteaddress.co.uk/mailtest.php' method='post'
    name='webform' id='webform'> <table width='500' border='0' cellspacing='0'
    cellpadding='5'> <tr> <td><div align='right' class='quotes'>First
    Name</div></td> <td><input name='FirstName' type='text'
    id='FirstName'></td> </tr> <tr> <td><div align='right'
    class='quotes'>Last Name </div></td> <td><input name='LastName'
    type='text' id='LastName'></td> </tr> <tr> <td><div
    align='right' class='quotes'>Email</div></td> <td><input name='Email'
    type='text' id='Email'></td> </tr> <tr> <td
    class='quotes'><div align='right'>Favourite color </div></td>
    <td><select name='Select[]' id='Select'> <option value='select'
    selected>Pick A Color</option> <option value='red'>Red</option>
    <option value='orange'>Orange</option> <option
    value='yellow'>Yellow</option> <option value='green'>Green</option>
    <option value='blue'>Blue</option> <option
    value='indigo'>Indigo</option> <option value='violet'>Violet</option>
    </select></td> </tr> <tr> <td valign='middle'><div
    align='right' class='quotes'>Favourite Foods </div></td> <td
    valign='top'><table width='301' border='0' cellspacing='0' cellpadding='0'>
    <tr> <td width='61'><input name='Food' type='checkbox'
    id='food' value='Italian'></td> <td width='61'><input name='Food'
    type='checkbox' id='food' value='Thai'></td> <td width='61'><input
    name='Food' type='checkbox' id='food' value='Chinese'></td> <td
    width='61'><input name='Food' type='checkbox' id='Food' value='French'></td>
    <td width='61'><input name='Food' type='checkbox' id='Food'
    value='Mexican'></td> </tr> <tr> <td
    width='61'><p>Italian</p></td> <td width='61'><p>Thai</p></td>
    <td width='61'><p>Chinese</p></td> <td
    width='61'><p>French</p></td> <td width='61'><p>Mexican</p></td>
    </tr> </table></td> </tr> <tr> <td
    valign='middle'><div align='right' class='quotes'>Cats or Dogs? </div></td>
    <td valign='top'><table width='200'> <tr> <td
    valign='top'><p> <label> <input type='radio'
    name='Pet' value='cats'> Cats</label> </p></td>
    </tr> <tr> <td valign='top'><p>
    <label> <input type='radio' name='Pet' value='dogs'>
    Dogs</label> </p></td> </tr> </table></td>
    </tr> <tr> <td valign='top'><div align='right'
    class='quotes'>Message</div></td> <td><textarea name='Message' rows='4'
    id='Message'></textarea></td> </tr> <tr> <td><div
    align='right'></div></td> <td><input type='submit' name='Submit'
    value='Send Details'></td> </tr> </table> </form> When I fill out
    the form and send the results, everything turns up correctly except two items.
    The Select item returns the result 'Array' and the checkboxes only return the
    last selected item. Here is the PHP I am using: <?php
    ini_set('sendmail_from', 'root@myaddress.co.uk'); $FirstName =
    $_POST['FirstName']; $LastName =$_POST['LastName']; $Email =
    $_POST['Email']; $Select = $_POST['Select']; $Food =
    $_POST['Food']; $Pet = $_POST['Pet']; $Msg = $_POST['Message'];
    $body = 'Email web form results\n\n Name: $FirstName $LastName\n\n
    Email: $Email\n\n Favourite Color: $Select\n\n Food: $Food\n\n Pet: $Pet\n\n
    Message: $Msg'; mail('me@myaddress.co.uk', 'Sample Web Form',
    '$body'); ?> I am fairly new to PHP and would be grateful for advice on
    how to collect the results when more than one choice is offered.

    Siriunson Guest

  2. Similar Questions and Discussions

    1. Collecting the data...
      I found this tutorial on Adobe... <a target=_blank class=ftalternatingbarlinklarge...
    2. Preflight Font Collecting
      Does software exist for preflight font collection with Illustrator CS and Panther 10.3.3? Markzware FlightCheck Designer 5.07 doesn't seem to work....
    3. Collecting data from the PDF forms
      Where I can find some sample scripts or some information on the scripts which will collect the data from the PDF form and send it by email or upload...
    4. collecting email addresses
      hi. I have a preview site up for my flash site that I am still building, but im wondering how to set up the preview so that people can enter their...
    5. Collecting Payment in ASP.Net via PayPal or similar???
      Hi all, I have an app that allows users to upload files to my site, and then download them at a later date. Once the files have been safely...
  3. #2

    Default Re: Collecting form data with PHP

    The two problems can be solved fairly easily. $select is an array. To see
    what's inside the array you need to loop through it. Try the following...
    body = 'Email web form results\n\n Name: $FirstName $LastName\n\n Email:
    $Email\n\n Favourite Color:'; foreach($select as $option) { $body .=
    $option.' '; } $body.=\n\n Food: $Food\n\n Pet: $Pet\n\n Message: $Msg';
    Just replace the line that begins $body= with all the above. Then your
    checkboxes are all called the same. Therefore the last value is overwriting the
    one before. Make sure that your checkboxes have different names and then you
    will be able to access them. Ross

    Ross Riley Guest

  4. #3

    Default Re: Collecting form data with PHP

    Ross - thanks for the reply. Here's the section of my new code: $FirstName =
    $_POST['FirstName']; $LastName =$_POST['LastName']; $Email =
    $_POST['Email']; $Select = $_POST['Select']; $Food =
    $_POST['Food1']; $Pet = $_POST['Pet']; $Msg = $_POST['Message'];
    $body = 'Email web form results\n\n Name: $FirstName $LastName\n\n
    Email: $Email\n\n Favourite Color: '; foreach($select as $option) {
    $body.= $option.''; } $body.=\n\n Food: $Food\n\n Pet:
    $Pet\n\n Message: $Msg'; Unfortunately something seems to be causing an
    error as submitting the form generates the following message:: Warning:
    Unexpected character in input: '\' (ASCII=92) state=1 in
    e:\domains\d\myaddress.co.uk\user\htdocs\mailtest. php on line 216 Warning:
    Unexpected character in input: '\' (ASCII=92) state=1 in
    e:\domains\d\myaddress.co.uk\user\htdocs\mailtest. php on line 216 Parse error:
    parse error, unexpected T_STRING in
    e:\domains\d\myaddress.co.uk\user\htdocs\mailtest. php on line 216 Have I
    mis-typed something

    Siriunson Guest

  5. #4

    Default Re: Collecting form data with PHP

    I have solved the problem with the help of an article I ; //extract the
    checkbox values and create a new variable $print_array to print all the results
    while (list ($key, $val) = each ($Food)) { $print_array .=$val .= '
    '; } while (list ($key, $val) = each ($Select)) {
    $color .=$val .= ' '; } $body = 'Email web form results\n\n
    Name: $FirstName $LastName\n\n Email: $Email\n\n Favourite Color: $color\n\n
    Food: $print_array\n\n Pet: $Pet\n\n Message: $Msg'; Thanks again Ross for
    your help.

    Siriunson Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139