Jump to content


Photo

php forms


  • Please log in to reply
1 reply to this topic

#1 arakuna

arakuna
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 10 May 2006 - 03:34 AM

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

#2 Stuie_b

Stuie_b
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts
  • LocationNewcastle, UK

Posted 10 May 2006 - 09:09 AM

[!--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,



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

hope it helps

Stuie
It's all in the manual :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users