ghi572000 Posted November 19, 2010 Share Posted November 19, 2010 Hi I am really getting with validating a drop down box in my form for posting I have set all the <options> in html form as followed: <form method="post" action="thankyou.php"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <select name="visitortitle"> <option>Please Select</option> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Dr">Dr</option> </select> </form> now I'm trying to find a way to validate it in the .php sending side and using this: <?php $visitortitle = $_POST['visitortitle']; if (!isset($visitortitle)) { echo $visitortitle; } mail("[email protected]", $subject, $message, $from); ?> I have tried so many different ways with - if (!isset - but cant get the send mail to recognise the drop down menu selection!!!! Any help would really be appreciated as I'm not that up on php coding. Thanks in advance. Gary Link to comment https://forums.phpfreaks.com/topic/219198-drop-down-box-in-a-form-post-php/ Share on other sites More sharing options...
litebearer Posted November 19, 2010 Share Posted November 19, 2010 just some rambling thoughts... <? $title_array = array("Mr", "Mrs", "Miss", "Ms", "Dr"); $visitortitle = $_POST['visitortitle']; if (!in_array($visitortitle, $title_array)) { /* send back to form */ } $to = "[email protected]"; $subject = "Hi!"; $message = "Dear " . $visitortitle; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); ?> Link to comment https://forums.phpfreaks.com/topic/219198-drop-down-box-in-a-form-post-php/#findComment-1136693 Share on other sites More sharing options...
jdavidbakr Posted November 19, 2010 Share Posted November 19, 2010 This section of code: if (!isset($visitortitle)) { echo $visitortitle; } is doing absolutely nothing - it's saying "If $visitortitle is nothing then echo nothing" and then continues on. So your code will do exactly the same thing whether visitortitle is selected or not. Link to comment https://forums.phpfreaks.com/topic/219198-drop-down-box-in-a-form-post-php/#findComment-1136696 Share on other sites More sharing options...
ghi572000 Posted November 19, 2010 Author Share Posted November 19, 2010 Thanks litebearer Your coding gave me some ideas and this has fixed it. <? $title_array = array("Mr", "Mrs", "Miss", "Ms", "Dr"); if (!in_array($visitortitle, $title_array)) { echo "<h2><br /><br /><br /><br />Please enter a title correctly<br />before you try submitting the form again.</h2>\n"; die ( '<a href="forum.html">click here go back and try again</a>' ); echo $id;} ?> Thanks Gary Link to comment https://forums.phpfreaks.com/topic/219198-drop-down-box-in-a-form-post-php/#findComment-1136785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.