Forum Moderators: coopster

Message Too Old, No Replies

Form data not passed to $ POST variables

         

iamlam1981

7:40 pm on Sep 12, 2010 (gmt 0)

10+ Year Member



Hi all,

I created an HTML form to be processed by a PHP script. No matter what I do, the data from the form is not passed to the $_POST variables. It's probably something very simple that I'm missing.

This is the form code:

<form action="contact.php" method="post" name="contact_us">
<label for="name">Your name:</label><br /><input name="name" value="" type="text" size="29" maxlength="75"/>
<br />
<br />
<label for="email">Your email: </label><br /><input name="email" value="" type="text" size="29" maxlength="100" />
<br />
<br />
<label for="message">Your message: </label>
<br />
<textarea name="message" cols="25" rows="5"></textarea>
<br />
<input name="user_submit" type="button" value="Submit" id="submit_btn" /><input name="form_clear" type="reset" value="Clear" id="clear_btn" />
</form>



And this is the PHP code:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['message'];
$message = "\n\n Name: ".$name."\n\n Email: ".$email."\n\n Message: ".$msg."\n\n Please contact them soon.";
echo "$message";

?>

A few things I have tried include changing to quotation marks in the $_POST variable ($_POST["name"]), as well as removing any quotes ($_POST[name]). I'm at a bit of a loss as it has been about 5 years since I last did any web design and programming.

Thank you in advance!

Matthew1980

7:52 pm on Sep 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there ianlam1981,

Welcome to WebmasterWorld!

Change this:-
<input name="user_submit" type="button" value="Submit" id="submit_btn" />

to this:-
<input name="user_submit" type="submit" value="Submit" id="submit_btn" />

You need to have a valid submit button for the form to work!

And in the php file:-

<?php
//catch the process & turn on error reporting..
error_reporting(E_ALL);

if(isset($_POST['submit']) && ($_POST['submit'] == "Submit")){
//Assign the vars & put through the strip_tags() function for more security
//not needed but good coding practise...

$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$msg = strip_tags($_POST['message']);

//build the var
$message = "\n\n Name: ".$name."\n\n Email: ".$email."\n\n Message: ".$msg."\n\n Please contact them soon.";

//echo to screen
echo "$message";
}
else{
//redirect back to form
header("Location: the_filename_of_your_form_page_here");
}
?>


Hope that makes sense.

Cheers,
MRb

iamlam1981

8:25 pm on Sep 12, 2010 (gmt 0)

10+ Year Member



Oh man...I cannot believe I missed the submit button thing. Thank you so much for the help--everything works perfectly now.

Matthew1980

8:26 pm on Sep 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there iamlam1981,

Cool, all sorted then.

Cheers,
MRb