Forum Moderators: coopster
In the HTML file I have a form field with two required fields and an unrequired one. I have a PHP script which mails the website owner the information that a user has submitted.
I would like a hidden field to display any errors or display a thank you message when the forms have been completed correctly. Right now, I have the Thank You part taking the user to a separate page.
I'm not 100% sure on how to pass a variable to an HTML page, and I feel terrible that I'm posting such an easy question. Since I'm on the topic, I've been reading the tutorials on HotScripts.com regarding Mailing List information. Anyone want to tell me his or her favorite resources? I also use php.net for a reference already.
HTML Information
=============
<form name="contact" method="post" action="includes/contact_send.php">
<input type="hidden" name="hiddenField" value="<?php $_POST['hiddenField'];?>"> <!--Error Message Area-->
<INPUT type="text" name="name" maxlength="50">
<INPUT type="text" name="email" maxlength="100">
<INPUT type="text" name="org" maxlength="50">
PHP
=============
<?
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$org = $_REQUEST['org'];
$hiddenField = 'You must fill out the Name & Email section';
if (!isset($_REQUEST['name'])) {
header("Location: contact.asp");
}
elseif (empty($email) ¦¦ empty($name)) {
$hiddenField = $_POST;
}
else {
mail("dude@thewebsite.com", "Contact Form Submission", "Name: $name\nEmail: $email\nOrganization: $org");
header( "thankyou.asp" );
}
?>
Basics of Submitting and Emailing Forms with PHP [webmasterworld.com]
Learning PHP - Books, Tutorials and Online Resources [webmasterworld.com]
if that baiscs thread doesn't really help then I, or any else, will be happy to walk through it
<?php
if($_POST["action"] == "Submit") {
$name = $_POST['name'];
$email = $_POST['email'];
$org = $_POST['org'];
if (empty(trim(($name))) {
$text = '<b>You must fill in the name section</b>';}
elseif (empty(trim($email))) {
$text = '<b>You must fill in the email section</b>';}
else {
mail("dude@thewebsite.com", "Contact Form Submission", "Name: $name\nEmail: $email\nOrganization: $org");
$text = '<b>THANK YOU!</b>';}}//else the form wasn't submitted. If you don't want to see the form again place here the else {?> html.....<? }?>
?>
<html....
<body><?php if($hiddenField) echo $text;?>
<form name="contact" method="post" action="includes/contact_send.php">
<INPUT type="text" name="name" maxlength="50">
<INPUT type="text" name="email" maxlength="100">
<INPUT type="text" name="org" maxlength="50">
<INPUT type="submit" name="action" value="Submit">
</html>