Menu list sendmail .php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ghi572000
Forum Newbie
Posts: 6
Joined: Mon Sep 20, 2010 4:02 pm

Menu list sendmail .php

Post by ghi572000 »

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

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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Menu list sendmail .php

Post by Celauran »

ghi572000 wrote:How can I get this code to recognise that a <option></option> has been selected?
Assign values to your options

Code: Select all

<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
etc.
ghi572000
Forum Newbie
Posts: 6
Joined: Mon Sep 20, 2010 4:02 pm

Re: Menu list sendmail .php

Post by ghi572000 »

Thanks Celauran

tried that but still did not work?

I have now got this far:

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 }

but now I am now getting the error message below:
Parse error: syntax error, unexpected '}' thankyou_forum.php on line 51
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Menu list sendmail .php

Post by s992 »

Remove the curly brace at the end of line 47.
ghi572000
Forum Newbie
Posts: 6
Joined: Mon Sep 20, 2010 4:02 pm

Re: Menu list sendmail .php

Post by ghi572000 »

Thanks again Celauran still did not help but here is the full view of my coding:


The code I'm using in the post html below:

<form method="post" action="thankyou_forum.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 ?>" />
<tr>
<td align="right">Title:</td>
<td>&nbsp;</td>
<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>
</tr>

<td>
<label>
<input name="button" type="submit" id="button" value="Send" />
</label>
</td>
</tr>
</form>


Okay now the code I have in the sendemail php page:

<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Please enter your message before you try submitting the form.");
}

if(isset($_POST['visitortitle'])) {$visitortitle = $_POST['visitortitle'];} else {$visitortitle = 'Nothing Selected';}
echo "<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>' );
}

$from = "From: $visitor\r\n";

$message = " $todayis [EST] \n
Title: $visitortitle \n ";

mail("name@domain.com", $visitortitle);

?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Menu list sendmail .php

Post by Celauran »

You still have an extraneous brace. If "Please hit the back button.." is supposed to display when $_POST['visitortitle'] is not set, you need to remove the brace after 'Nothing Selected'. Otherwise, you have an unmatched closing brace after die()
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Menu list sendmail .php

Post by s992 »

You didn't remove the brace:

Code: Select all

if(isset($_POST['visitortitle'])) {
	$visitortitle = $_POST['visitortitle'];
} else {
	$visitortitle = 'Nothing Selected';
} // This brace closes the else
echo "<h2>
Please hit the back button and fill in your full name correctly
before you try submitting the form again.</h2>\n";
die ( '<a href="forum.html">click here go back and try again</a>' );
} /* This brace does not close anything is causing your syntax error. Judging from your code,
this brace should stay put and you should remove the brace after you set $visitortitle = 'Nothing Selected' */
EDIT: Celauran beat me to it. Damn.
ghi572000
Forum Newbie
Posts: 6
Joined: Mon Sep 20, 2010 4:02 pm

Re: Menu list sendmail .php

Post by ghi572000 »

Thanks s92 but the problem I am still having is when I send the <option value=""></option> tag is not recognised as it doesn't pass if(isset

From my code any other suggestions?

Thanks
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Menu list sendmail .php

Post by s992 »

I've got no problems running it after taking out that brace...

Based on your form processing page, it looks like your form has a lot more to it than just the visitor type. Maybe the error lies somewhere in there?
Post Reply