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!
hi, im sure this has been discussed here before, but i tried searching and can't come up with the right words to find what to do.
my problem is that i have a form, and when i post it, php will check if everything is valid before sending out an email, but if things are not valid it will give you the proper error message and reload the form page. all this works fine, but how would i put all the information they have already entered back into the new form page?
//EMAIL FORM
function email_form()
{
?>
<form method="post" action="feedback.php">
Subject:
<SELECT name="topic">
<Option value="General feedback"> General feedback </option>
<Option value="Help with the website"> Help with the website </option>
<Option value="Help with an order"> Help with an order </option>
</SELECT>
<br><br>
Message:<br>
<TEXTAREA name="message" rows="6" cols="40"></textarea><br>
<br>
If you would like a reply please enter your email address here:<br>
<input type="text" name="from" cols=15></input><br>
<input type="submit" name="submit" value="submit"></input>
</form>
<?
}
//PAGE START
//if submit has been clicked
if ($submit)
{
if(!$message) //no message
{
echo "<b style='color:FF0000'> *Message cannot be blank</b><br><br>";
email_form();
}
else
{
if(!$from) //allowing blank from field for annonymous users
{
send_email($message, $from, $topic);
}
else
{
if(!valid_email($from)) //invalid email (user typo maybe)
{
echo "<b style='color:FF0000'> *Invalid email address</b><br><br>";
email_form();
}
else
{
//All checks have been made, you pass
send_email($message, $from, $topic);
}
}
}
}
else
{
//first time page view
email_form();
}
?>
set up an argument list to pass into email_form() with default values set to empty strings. Send it all the variables when calling it (outside of the one that isn't or whatever)
I'd advise rewriting your code to support register_globals being off however..
$option[0] = "I need help placing an order";
$option[1] = "I have a question about an existing order";
$option[2] = "I cannot find the items I need";
$option[3] = "I am having technical difficulty with the website";
$option[4] = "Other / General feedback";
?>
<form method="post" action="contact_us.php">
Subject:
<SELECT name="topic">
<?
for($i=0; $i < count($option); $i++)
{
if($option[$i] == $topic)
echo "<Option value=\"".$option[$i]."\" selected> ".$option[$i]." </option>";
else
echo "<Option value=\"".$option[$i]."\"> ".$option[$i]." </option>";
}
?>
</SELECT>
and i know i should not be using global variables, but they just seem so harmless for this script. and besides i never properly learned the other way even though it's probably just as easy.
it's actually pretty easy to not use global variables. On the page that your form submits to, (even if it's the same page), and if your using the method get then do the following..