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@domain.com", $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
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 = "recipient@example.com"; 
$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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.