Jump to content

form tutorial


rnintulsa

Recommended Posts

I am new to php and have found phpfreaks to be a valuable teacher. 

 

I have been working for days trying to find a simple form tutorial. 

Either they seem to be unsecure, or they are to complicated for me.

 

I have searched phpfreaks and can't find one there either.

 

Here is my form.htm:

<form action="estimate_process.php" method="post">

	<input type="hidden" name="recipient" value="renee">
	<input type="hidden" name="subject" value="Estimate Request Form">
	<input type="hidden" name="redirect" value="estimate_thankyou.htm">


	<table >
		<tr>
			<th>Name - REQUIRED</th>
			<th>E-mail Address - REQUIRED</th>
		</tr>

		<tr>
			<td>
				<input name="name" type="text" id="name" size="40" maxlength="50">
			</td>
			<td>
				<input name="email" type="text" id="email" size="40" maxlength="50">
			</td>
		</tr>

		<tr>
			<th>Company Name - REQUIRED</th>
			<th>Phone Number</th>
		</tr>
		<tr>
			<td>
				<input name="company_name" type="text" id="company_name" size="40" maxlength="50">
			</td>
			<td>
				   <input name="phone" type="text" id="phone" size="40" maxlength="12">
			</td>
		</tr>

		<tr>
			<th><strong><br>Desired Service - </strong>check all that apply</th>				
		</tr>
		<tr>
			<td>
				<input type="checkbox" name="new web" value="Web Design">New Website Design
			</td>
			<td>
				<input type="checkbox" name="htmlandflash" value="html and flash">HTML design with Macromedia Flash elements
			</td>
		</tr>
		<tr>
			<td>
				<input type="checkbox" name="redesign" value="redeisgn">Re-Design of existing web site
			</td>
			<td>
				<input type="checkbox" name="ecommerce" value="e-commerce">e-commerce site
			</td>
		</tr>
		<tr>
			<td>
				<input type="checkbox" name="changecontent" value="change content">Retain existing web site - change content/elements
			</td>
			<td>
				<input type="checkbox" name="graphics" value="Graphics Design">Graphic Design
			</td>
		</tr>
		<tr>
			<td>
				<input type="checkbox" name="fullflash" value="flash only">Fully interactive Macromedia Flash design
			</td>
			<td>
				<input type="checkbox" name="video" value="Video Editing">Video Editing
			</td>
		</tr>
                        <tr>
			<td><br><input name="Submit" type="submit" value="Submit">
          <input type="reset" name="reset" value="Reset"><br><br><br>
			</td>
		</tr>
	</table>

 

I thought I would use some javascript for the required fields, and have tried putting it in different places.

Not sure exactly it should go:

//All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. 
$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];
$company_name = $HTTP_POST_VARS['company_name'];
	// Checks that the Email field contains a valid email address and the Subject field isn't empty. Regular expression match. 
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<h4>Please enter a valid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($name == "") {
  echo "<h4>Please enter your Name</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($company_name == "") {
  echo "<h4>Please enter your Company Name</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
}
	// Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. 
elseif (mail($email,$name,$company_name)) {
  header( 'Location: estimate_thankyou.htm' ) ;
} else {
  echo "<h4>Can't send email to $email</h4>";
}

 

Then there is this code for my estimate_process.php page, that I chose to use because the explanations were really good and understandable.  This stuff has to make sense to me or else I am not learning.:

<?PHP
error_reporting(E_ALL);

define('CHECK_REFERER', true);//defines if script should do referer checking. "false" could cause your script to become an open relay 

$referers = array('cox.net', 'www.cox.net', 'www.host.net', 'host.net'); // This array allows you to define the domains that you will allow forms to reside on and use

$recipient_array = array('renee' => 'my email'); //This array allows you to list valid key/value pairs of e-mail addresses so you don't have to expose your e-mail address to the net


$valid_env = array('REMOTE_HOST', 'REMOTE_ADDR', 'REMOTE_USER', 'HTTP_USER_AGENT'); //This array allows you to define enviromental variables that can be reported.
?>

Why is it that this code does not send the form to my email address, and why does it give me a blank estimate_process.php page rather than redirecting to the estimate_thankyou.php page?

 

 

But...when I put the Javascript at the end of the processing page it does redirect, but still does not send the form to my email.

 

Please school me, or point me to a good tutorial.

 

Thanks ahead of time everyone.

 

 

 

Link to comment
Share on other sites

I'm not sure where your getting your tutorials from but they seem outdated. $HTTP_POST_VARS has long been replaced with $_POST.

 

There is a book in my signiture, Hudzilla. Its free and has an entire chapter dedicated to dealing with forms through php.

Link to comment
Share on other sites

The book was great, way over my head. 

 

The tizag link was more my speed, but it didn't send to an email, but I

am going to work with it and try to add what I need, and take out what I

don't.

 

If anyone else can help me with the above code, or point me to a tutorial for a simple

contact form that validates I would sooo appreciate it. I am losing heart, but I am not ready to give up yet.

 

 

 

Thanks a million.

Link to comment
Share on other sites

The book was great, way over my head.

 

Likely because you just jumped straight into the middle. The book (like most) is designed to be read from cover to cover itroducing concepts in a logical order so by the time you get to the end everything makes sense.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.