Jump to content

Drop Down Box in a Form Post .php


ghi572000

Recommended Posts

Hi I am really getting  :confused: 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

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>"); 
?>

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.