Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

online forms and php

Status
Not open for further replies.

Halcrow

Programmer
Aug 24, 2004
76
GB
i am creating an online form that submits data to me via email using a php file. Everything works fine when I submit "text" inputs (<input type="text" name="myname" />) but I get my error page when I try to include "select" boxes.

In my code I have: (for example)
<form method="post" action="contact.php">
...
<select name="year">
<option>2004</option>
<option>2005</option>
</select>

In my php file I have:
$year = $_POST['year'] ;
...
$messageproper =
...
"\n\nYear: " . $year . "


The idea is that it should tell me what year was selected in the email I recieve. What am I doing wrong?
 
Hi Halcrow,

You have left out value identifiers from the option tags. It should look like this:

Code:
<form method="post" action="contact.php">
...
<select name="year">
  <option value="2004">2004</option>
  <option value="2005">2005</option>
</select>
...
</form>

Good Luck!


Jakob
 
thanks for the tip Jakob.

I've now included those value tags but I still unfortunately encounter the same problem...

cheers
Calum
 
Hi,

Strange .... try this:

Code:
$year = $_REQUEST["year"];

This should work in any case.


Jakob
 
thanks again, but still nothing :( I actually have this line in my messageproper:

"\n\n-Date: " . $day . " " . $month . " " . $year . "

and I input, well as you can see, day, month and year. Is this correct syntax?

and...how do you get those little "code" boxes up in the posts?

Cheers
Calum
 
Hmmmm .... try posting the form part of your HTML file and the part of the PHP that I need to know about.

Code boxes - To get this:

Code:
... some code here ...

You type this:

[tt][ignore][[/ignore]code[ignore]][/ignore] ... some code here ...[ignore][[/ignore]/code[ignore]][/ignore][/tt]

This actually have a name : TGML, or Tecumseh Group Markup Language.

Here's a reference on TGML:

Jakob c",)
 
ok, here's a couple of chunks...!

Code:
<form method="post" action="booking.php"> 
<fieldset> 
<legend>Fill in the details below.</legend> 
<br/><br />

<label>Name:<br /><input type="text" name="name" /></label><br />
<label>Organisation:<br /><input type="text" name="org" /></label><br /> 
<label>Email:<br /><input type="text" name="email" /></label><br />
<label>Telephone:<br /><input type="text" name="phone" /></label><br />
<label>Planned Date of Visit:</label><br />

<label>Day: </label>
<select name="day">
	<option value="01">01</option>
	<option value="02">02</option>
	<option value="31">31</option>
</select>
<label>Month: </label>
<select name="month">
	<option value="Jan">Jan</option>
	<option value="Feb">Feb</option>
</select>
<label> Year: </label>
<select name="year">
        <option value="2004">2004</option>
	<option value="2005">2005</option>
	<option value="2006">2006</option>
</select>
<br />
<br />
<label class="long">Additional Information:<br />
<textarea name="info" rows="5" cols="43"></textarea></label>
<br />
<input type="submit" value="Submit" class="submit" /> <br /><br />
</fieldset> 
</form>

php:
Code:
$formurl = "[URL unfurl="true"]http://???.com/index.shtml"[/URL] ;
$errorurl = "[URL unfurl="true"]http://com/error.shtml"[/URL] ;
$thankyouurl = "[URL unfurl="true"]http://???.com/thankyou.shtml"[/URL] ;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$name = $_POST['name'] ;
$org = $_POST['org'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$info = $_POST['info'] ;
$day = $_REQUEST['day'] ;
$month = $_REQUEST['month'] ;
$year = $_REQUEST['year'] ;


$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) { 
	header( "Location: $formurl" );	exit ;}

if (empty($info)) { header( "Location: $errorurl" );exit ;}

if (get_magic_quotes_gpc()) {
	$info = stripslashes( $info );

}

$messageproper =

	"This message was sent from:\n" .
	"$http_referrer\n" .
	"\n----------- Booking Info from a ??? Visitor ----------------\n\n" .
	"\n\nThis form was sent from ???" .
	"\nreply to send an email to the comment provider, if they have" .
	"\nentered an email address." .
	"\n\n" .
	"\n\n-Submitted by: " . $name . "
	"\n\n-Organisation: " . $org . "
	"\n\n-Email: " . $email .
	"\n\n-Phone: " . $phone . "
	"\n\n-Date: " . $day . "  " . $month . "  " . $year . "
	"\n\n-Additional Information: \n" . $info .
	"\n" .
	"\n---------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.02" );
header( "Location: $thankyouurl" );
exit ;

I've dumped most of it there! Have a look (sorry its quite large)

Calum
 
Code:
 "\n\n-Submitted by: " . $name . [red]"[/red]
    [red]"[/red]\n\n-Organisation: " . $org . "
    "\n\n-Email: " . $email .
    "\n\n-Phone: " . $phone . "


You have overlapping quotes.

"I'm making time
 
:) yes yes, I see now!

I must admit I have no experience with php and just modified another file!

Thankyou for pointing that out tho Foamcow.

Calum
 
There were a couple more too, but I left them for you to find ;-)

Often it takes a fresh eye to spot things like that.

next time post the actual error message, they can be helpful ;-)

"I'm making time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top