+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
Coding Thread, drop down list in a html webform and php in Coding and Web Development; Hi all i want to create a web form with a drop down list and have and have it sent ...
  1. #1

    Join Date
    Oct 2006
    Location
    uk
    Posts
    494
    Thank Post
    19
    Thanked 3 Times in 2 Posts
    Rep Power
    17

    drop down list in a html webform and php

    Hi all i want to create a web form with a drop down list and have and have it sent to my email. I have created standard html form and the php file that sends it to my email which works ok, for all the text boxex in the form but when i add a drop down list menu to the form the results don't come through as there is no coresponding php code in the php file and i don't how to do this, can anyone help please?

    thanks in advance

  2. #2
    Jona's Avatar
    Join Date
    May 2007
    Location
    Cranleigh
    Posts
    471
    Thank Post
    14
    Thanked 51 Times in 49 Posts
    Rep Power
    24
    This might help:
    http://www.w3schools.com/tags/tag_option.asp

    If you set an id / name in the option tag you should be able to read the value it's assigned just like any other field.

    Cheers
    Jona

  3. Thanks to Jona from:

    Uraken (5th March 2008)

  4. #3
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    Might be worth posting your code so a bit of debugging can be done

  5. #4
    Ryan's Avatar
    Join Date
    Jan 2008
    Location
    Scotland
    Posts
    537
    Thank Post
    12
    Thanked 16 Times in 15 Posts
    Blog Entries
    1
    Rep Power
    29
    I've done something like this recently for a couple of little projects. I'll post again when i get home.

    Where's the contents of your list coming from? Database/file or hand-coded?

  6. #5

    Join Date
    Oct 2006
    Location
    uk
    Posts
    494
    Thank Post
    19
    Thanked 3 Times in 2 Posts
    Rep Power
    17
    thanks for the replys all the code is enclosed i save it all as a php file upload and most works just not the drop down bit:
    //begin code
    <?php

    // Only show error messages, not the warnings...
    ini_set("error_reporting", "E_ALL & ~E_NOTICE");

    // E-mail address to which the form will be sent...
    $form_email = "email@email.com";

    if ($_POST['envoi']) {

    // E-mail headers:
    $headers ="MIME-Version: 1.0 \n";
    $headers .="From: website<email@email.com>\n";


    $headers .="Content-Type: text/html; charset=iso-8859-1 \n";

    $subject = "Enqu iryFrom website";

    $header_part = "<html><head>
    <meta http-equiv=Content-Type content=text/html; charset=iso-8859-1>
    </head>
    <body bgcolor=#FFFFFF>";

    for ($a=1; $a<= $_POST['text_field_number']; $a++) {
    $text_fields_part .= "<font face='Verdana' size='2' color='#003366'>" . $_POST['field_title'.$a] . " = " . $_POST['field'.$a] . "</font><br>";
    }

    if ($_POST['email_field_number'] != 0) {
    $email_field_part = "<font face='Verdana' size='2' color='#003366'>" . $_POST['email_title'] . " = " . $_POST['email_field'] . "</font><br>";
    }

    if ($_POST['textarea_number'] != 0) {
    $text_area_field = "<font face='Verdana' size='2' color='#003366'>" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . "</font><br>";
    $text_area_field = stripslashes($text_area_field);
    }

    $end = "</body></html>";

    $output = $header_part . $text_fields_part . $email_field_part . $text_area_field . $end;

    // Send the e-mail
    if (@!mail($form_email,$subject,$output,$headers)) {
    echo("Cannot send the form");
    } else { // Closing if !mail...

    // Redirect to the thank you page
    header("Location:thankyou.html");
    exit();

    } // Fin du else
    } // Closing if edit
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">function checkSelection() {} // End of function

    </script></head>

    <body><form name="mail_form" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="return checkSelection()">
    <div align="center"></div>
    <p align="center">
    <table width="566" border="0" align="center">
    <p align="center">
    </p><tr>
    <td><font face="Verdana" size="2">How many Beds</font></td>
    <td><select id= "people" name="people" size="1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="3">4</option>
    <option value="3">5</option>
    </select> </td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many large Boxes</font></td>
    <td><input name="field2" type="text"></td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many wardrobes</font></td>
    <td><input name="field3" type="text"></td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many pianos</font></td>
    <td><input name="field4" type="text"></td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many small boxes</font></td>
    <td><input name="field5" type="text"></td>
    </tr><tr>
    <td width><font face="Verdana" size="2">Email Address</font></td>
    <td width><input name="email_field" type="text"></td>
    </tr><tr>
    <td valign="top"><font face="Verdana" size="2">Any other info here please</font></td>
    <td><textarea name="textarea_field" cols="50" rows="10"></textarea></td>
    </tr><tr>
    <td valign="top"><input name="text_field_number" type="hidden" id="text_field_number" value="5">
    <input name="textarea_number" type="hidden" value="1">
    <input name="email_field_number" type="hidden" value="1">
    <input name="field_title1" type="hidden" value="How many Beds"><input name="field_title2" type="hidden" value="How many large Boxes"><input name="field_title3" type="hidden" value="How many wardrobes"><input name="field_title4" type="hidden" value="How many pianos"><input name="field_title5" type="hidden" value="How many small boxes"><input name="email_title" type="hidden" value="Email Address"><input name="textarea_title" type="hidden" value="Any other info here please"></td>
    <td><div align="center">
    <input type="reset" name="Reset" value="Clear">
    <input type="submit" name="envoi" value="Submit">
    </div></td>
    </tr>
    </table>
    <div align="center"></div>
    </form>

    </body>
    </html>
    //end code

  7. #6
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    In the bit where you are fetching the submitted variables (using $_POST) I don't see where you are fetching the 'people' variable which would be filled with the value from the drop down box.
    This could be why you do not get this value in the email.

  8. #7
    Ryan's Avatar
    Join Date
    Jan 2008
    Location
    Scotland
    Posts
    537
    Thank Post
    12
    Thanked 16 Times in 15 Posts
    Blog Entries
    1
    Rep Power
    29
    Yep, as Shane says, you need to be pulling that information back in. There's nothing being passed from the dropdown selection.

    And i won't mention the use of the deprecated FONT tag or the replication of code at this point

  9. #8

    Join Date
    Oct 2006
    Location
    uk
    Posts
    494
    Thank Post
    19
    Thanked 3 Times in 2 Posts
    Rep Power
    17
    Hi chaps i'm not sure if i gave the impression i wrote this myself (god no, i wish i was that clever) so please assume very little coding knowledge and feel free to point out the errors, as well as guidance as to how to put them right.
    Can you show me the code i need to add please?

  10. #9
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    Quote Originally Posted by Ryan View Post
    And i won't mention the use of the deprecated FONT tag or the replication of code at this point
    Damn another rule from Fight Club that I've failed!

  11. #10
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    After:

    if ($_POST['textarea_number'] != 0) {
    $text_area_field = "<font face='Verdana' size='2' color='#003366'>" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . "</font><br>";
    $text_area_field = stripslashes($text_area_field);
    }

    Put something like:

    $text_area_field = $text_area_field." <br>People:".stripslashes($_POST['people'])."<br>";

    But you may need to do more to sort out stopping people from adding naughty code etc
    (I am going over in my head the crudeness that I have used but I have to run now, sorry!)
    Last edited by Shane; 4th March 2008 at 05:59 PM.

  12. #11

    Join Date
    Oct 2006
    Location
    uk
    Posts
    494
    Thank Post
    19
    Thanked 3 Times in 2 Posts
    Rep Power
    17
    i tried that line of code shane it returns the all the text boxes but nothing for the drop down although it does now say the word people at the bottom of the email message now.
    I'm lost now and in above my head i think.

  13. #12
    alan-d's Avatar
    Join Date
    Aug 2005
    Location
    Sutton Coldfield
    Posts
    2,421
    Thank Post
    360
    Thanked 258 Times in 189 Posts
    Rep Power
    76
    Not an answer to your question but I spotted this

    $subject = "Enqu iryFrom website";
    move the space from between the 'u' and 'i' and put it after the 'y'


  14. Thanks to alan-d from:

    Uraken (5th March 2008)

  15. #13
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    //begin code
    <?php

    // Only show error messages, not the warnings...
    ini_set("error_reporting", "E_ALL & ~E_NOTICE");

    // E-mail address to which the form will be sent...
    $form_email = "email@email.com";

    if ($_POST['envoi']) {

    // E-mail headers:
    $headers ="MIME-Version: 1.0 \n";
    $headers .="From: website<email@email.com>\n";


    $headers .="Content-Type: text/html; charset=iso-8859-1 \n";

    $subject = "Enqu iryFrom website";

    $header_part = "<html><head>
    <meta http-equiv=Content-Type content=text/html; charset=iso-8859-1>
    </head>
    <body bgcolor=#FFFFFF>";

    for ($a=1; $a<= $_POST['text_field_number']; $a++) {
    $text_fields_part .= "<font face='Verdana' size='2' color='#003366'>" . $_POST['field_title'.$a] . " = " . $_POST['field'.$a] . "</font><br>";
    }

    if ($_POST['email_field_number'] != 0) {
    $email_field_part = "<font face='Verdana' size='2' color='#003366'>" . $_POST['email_title'] . " = " . $_POST['email_field'] . "</font><br>";
    }

    if ($_POST['textarea_number'] != 0) {
    $text_area_field = "<font face='Verdana' size='2' color='#003366'>" . $_POST['textarea_title'] . " = " . $_POST['textarea_field'] . "</font><br>";
    $text_area_field = stripslashes($text_area_field);
    }

    $text_area_field = $text_area_field."<br>People:".stripslashes($_POST['people'])."<br>";

    $end = "</body></html>";

    $output = $header_part . $text_fields_part . $email_field_part . $text_area_field . $end;

    // Send the e-mail
    if (@!mail($form_email,$subject,$output,$headers)) {
    echo("Cannot send the form");
    } else { // Closing if !mail...

    // Redirect to the thank you page
    header("Location:thankyou.html");
    exit();

    } // Fin du else
    } // Closing if edit
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">function checkSelection() {} // End of function

    </script></head>

    <body><form name="mail_form" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="return checkSelection()">
    <div align="center"></div>
    <p align="center">
    <table width="566" border="0" align="center">
    <p align="center">
    </p><tr>
    <td><font face="Verdana" size="2">How many Beds</font></td>
    <td><select id= "people" name="people" size="1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="3">4</option>
    <option value="3">5</option>
    </select> </td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many large Boxes</font></td>
    <td><input name="field2" type="text"></td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many wardrobes</font></td>
    <td><input name="field3" type="text"></td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many pianos</font></td>
    <td><input name="field4" type="text"></td>
    </tr><tr>
    <td><font face="Verdana" size="2">How many small boxes</font></td>
    <td><input name="field5" type="text"></td>
    </tr><tr>
    <td width><font face="Verdana" size="2">Email Address</font></td>
    <td width><input name="email_field" type="text"></td>
    </tr><tr>
    <td valign="top"><font face="Verdana" size="2">Any other info here please</font></td>
    <td><textarea name="textarea_field" cols="50" rows="10"></textarea></td>
    </tr><tr>
    <td valign="top"><input name="text_field_number" type="hidden" id="text_field_number" value="5">
    <input name="textarea_number" type="hidden" value="1">
    <input name="email_field_number" type="hidden" value="1">
    <input name="field_title1" type="hidden" value="How many Beds"><input name="field_title2" type="hidden" value="How many large Boxes"><input name="field_title3" type="hidden" value="How many wardrobes"><input name="field_title4" type="hidden" value="How many pianos"><input name="field_title5" type="hidden" value="How many small boxes"><input name="email_title" type="hidden" value="Email Address"><input name="textarea_title" type="hidden" value="Any other info here please"></td>
    <td><div align="center">
    <input type="reset" name="Reset" value="Clear">
    <input type="submit" name="envoi" value="Submit">
    </div></td>
    </tr>
    </table>
    <div align="center"></div>
    </form>

    </body>
    </html>
    //end code

  16. #14
    Shane's Avatar
    Join Date
    Apr 2007
    Location
    Kernow
    Posts
    166
    Thank Post
    23
    Thanked 14 Times in 12 Posts
    Rep Power
    22
    If you can try that out and post back here with any errors (Sorry I dont have access to the Apache server at the moment so can't test it out).
    Cheers

    (May need to remove the line: ini_set("error_reporting", "E_ALL & ~E_NOTICE"); to see the any errors)
    Last edited by Shane; 5th March 2008 at 10:20 AM.

  17. Thanks to Shane from:

    Uraken (5th March 2008)

  18. #15

    Join Date
    Oct 2006
    Location
    uk
    Posts
    494
    Thank Post
    19
    Thanked 3 Times in 2 Posts
    Rep Power
    17
    hi shane thanks that works now although it returns it at the bottom like this:

    How many Beds =
    How many large Boxes = 3
    How many wardrobes = 3
    How many pianos = 3
    How many small boxes = 3
    Email Address = a@bc.com
    Any other info here please = fsgdf

    How many beds:2

    p.s if i have more than one drop down can i assume i repeat the syntax with the new select id?

    thanks again



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Webform reply to address
    By HodgeHi in forum Web Development
    Replies: 2
    Last Post: 24th November 2007, 03:52 PM
  2. Cisco to Drop Linksys Brand
    By FN-GM in forum IT News
    Replies: 6
    Last Post: 1st August 2007, 09:21 PM
  3. PHP, MySQL, Webform, idiots guide.
    By Quackers in forum Coding
    Replies: 2
    Last Post: 5th June 2007, 09:03 AM
  4. Drop your messenger addys in here
    By Kyle in forum General Chat
    Replies: 22
    Last Post: 17th February 2007, 03:57 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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