Jump to content

Menu list sendmail .php


ghi572000

Recommended Posts

Hi I am having a problem with the code below I am using to send a simple php email form.

 

I am not that advanced with php but I want to add a drop down menu to a form I created and not sure how to get get the message (warning not completed) in the field -  if(empty($visitortitle)) {  - to accept or not to accept?

 

This is the code in the form:

 

<td align="left"><select name="visitortitle">

                              <option>Please Select</option>

                              <option>Mr</option>

                              <option>Mrs</option>

                              <option>Miss</option>

                              <option>Ms</option>

                              <option>Dr</option>

                            </select>

 

This is the code I have got in the sendemail:

 

if(empty($visitortitle)) {

echo "<h2><br /><br /><br /><br />Please hit the back button and enter the title drop down box correctly<br />before you try submitting the form again.</h2>\n";

die ( '<a href="forum.html">click here go back and try again</a>' );

}

 

How can I get this code to recognise that a <option></option> has been selected?

 

Any help would be appreciated.

 

Thanks

Gary

Link to comment
https://forums.phpfreaks.com/topic/218983-menu-list-sendmail-php/
Share on other sites

Not too good at php myself, but it looks like you forgot the values in the html code:

 

<td align="left"><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>

 

Might help.

 

 

Hi Coupe-r

 

tried this and also added <option value> but still no luck?

 

When I add $visitortitle = $_POST['visitortitle']; its just skips the menu completely.

 

Can I try something else, I think maybe something needs to be added to this code?

 

if(empty($visitortitle)) {

echo "<h2><br /><br /><br /><br />Please hit the back button and enter the title drop down box correctly<br />before you try submitting the form again.</h2>\n";

die ( '<a href="forum.html">click here go back and try again</a>' );

}

 

 

just try this and see what is echoed.  NOTE -- You will need a submit button to initiate the action as well as this drop down and button being inside a <FORM> tag.

 

//IN YOUR PHP

 

if(isset($_POST['visitortitle']))  {$visitortitle = $_POST['visitortitle'];} else {$visitortitle = 'Nothing Selected';}

 

echo $visitortitle;

 

 

 

// IN YOUR HTML

<td align="left"><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>

</td>

Coupe-r

 

Added the code as you suggested:

 

if(isset($_POST['visitortitle']))  {$visitortitle = $_POST['visitortitle'];} else {$visitortitle = 'Nothing Selected';}

echo $visitortitle; "<h2><br /><br /><br /><br />Please hit the back button and fill in your full name correctly<br />before you try submitting the form again.</h2>\n";

die ( '<a href="forum.html">click here go back and try again</a>' );

}

 

I am now getting this error message below but not shaw what you mean when you say:

NOTE -- You will need a submit button to initiate the action as well as this drop down and button being inside a <FORM> tag.

 

This is my send in the html page:

<input name="button" type="submit" id="button" value="Send" />

 

Sorry Coupe-r

 

this is the error message when sending:

Parse error: syntax error, unexpected '}' thankyou_forum.php on line 51

 

47  if(isset($_POST['visitortitle']))  {$visitortitle = $_POST['visitortitle'];} else {$visitortitle = 'Nothing Selected';}

48  echo $visitortitle; "<h2><br /><br /><br /><br />Please hit the back button and fill in your full name correctly<br

49  />before you try submitting the form again.</h2>\n";

50  die ( '<a href="forum.html">click here go back and try again</a>' );

51  }

 

 

 

 

Well, you can get rid of line 51, that doesn't encapsulate anything.

 

Also, you need more to your code than what you posted.

 

You need a submit button, a form tag and your drop down box.  When you press the submit button, your $visitortitle variable will get written and echo what you want.

 

What you have now is just a drop down box that you can choose different options.  You have no submission method?

Coupe-r

 

Do you mean I need to add something to this code below in my html page as I think I already have the form method as post?

 

<form method="post" action="thankyou_forum.php">

 

<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>

 

<input name="button" type="submit" id="button" value="Send" />

 

</form>

 

Not sure what you mean?

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.