Jump to content

php forms


arakuna

Recommended Posts

Hi,

I am trying to test a form on my web space. I have asked the isp about php forms and they said

"PHP scripts should be treated as cgis, therefore you should make them executable as you would a perl or shell script. Failure to do this willprobably result in the display of an 'internal server error'

We recommend permissions of 705."

Question 1. How do I make a php form executable and how do I set the permissions.

Question 2. Do I need to save the php form as a cgi?

Question 3. How can I get the below form to send an email to the person who fills out the form and a email to me also?

Feedback.html

<html>
<head>
<title>Feedback</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Please complete this form to submit your feedback. <br />
<form action="handle_form.php" method="post">
Mrs
<input name="titile" type="radio" value="Mrs" />
Mr
<input name="title" type="radio" value="Mr" />
Miss
<input name="title" type="radio" value="Miss">
Ms
<input name="title" type="radio" value="Ms" />
<br />
<br />
Name:
<input name="name" type="text" size="20" />
<br />
<br />
Email Address: <input name="email" type="text" size="20" />
<br />
<br />
Response:
<select name="response">
<option value="excellent">This is excellent.</option>
<option value="okay">This is okay.</option>
<option value="boring">This is boring.</option>
</select>
<br />
<br />
Comments: <textarea name="comments" cols="30" rows="3"></textarea>
<br />
<input type="submit" name="submit" value="Send my feedback" />


</form>
</body>
</html>

handle_form.php

<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1 />
<title>Your Feedback</title>
</head>

<body>
<?php
//handle_form.php
//This page recieves the data from feedback.html.
//It willreceive :title, name, email, response, comments, and submit.
//Adjust for register_globals being off

ini_set ('display_errors',1); //let me learn from my mistakes.
print "Thank you {$_POST['title']]
{$_POST['name']] for your comments. <br />";
print "You stated that you found this example to be {$_POST['response']] and added: {$_POST['comments']]";
?>
</body>
</html>
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Question 1. How do I make a php form executable and how do I set the permissions.[/quote]

Php files are compiled at runtime by the php compiler and dont need to be compiled by you. Setting file permisions needs to be done on the server, ususally by an ftp client or ssh and is known as CHMODing look at your ftp clients manual for info on to do this.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Question 2. Do I need to save the php form as a cgi?[/quote]

No, save it as a php file.


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Question 3. How can I get the below form to send an email to the person who fills out the form and a email to me also?[/quote]


Replace your handle_form.php file with the following code,



[code]<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1 />
<title>Your Feedback</title>
</head>

<body>
<?php
//handle_form.php
//This page recieves the data from feedback.html.
//It willreceive :title, name, email, response, comments, and submit.
//Adjust for register_globals being off
ini_set ('display_errors',1); //let me learn from my mistakes.


$msg = "Thank you $_POST['title']] $_POST['name']] for your comments. <br />";
$msg .= "You stated that you found this example to be $_POST['response'] and added: $_POST['comments']";


mail($_POST['email'],"Thank you",$msg,"FROM: webmaster@yourdomain.com"); //Send email to them
mail('YOUR EMAIL ADDRESS',"Feedback left",$msg,"FROM: webmaster@yourdomain.com"); //Send email to you, you could use a different message if you wish
echo $msg; //Display the message to browser (same as email)
?>
</body>
</html>[/code]

hope it helps

Stuie
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.