Jump to content

PHP - Web forms handling


robmo

Recommended Posts

Hi,

 

I have an HTML form created using Dreamweaver and now I need a script to handle the form processing. Basically what I need is for the form data received from the webpage to be organized in an email and then sent to me. I would also like to display a thank you message in the browser so the user knows it was received. I was planning to do this using CGI but a colleague suggested that CGI is old school and nowadays a developer would use PHP for this task. Is PHP the right solution for this project?

 

The examples I have found so far always include the HTML for the form and the script needed to handle it in one file. In my case, I have an HTML form already in place and need it to work with a script to perform the email function. I know I need to set "Action=" on my webpage to point to the PHP script but what would the code look like if no HTML is needed? I hope this makes sense...

 

Thanks for your help!

Rob

Link to comment
https://forums.phpfreaks.com/topic/209702-php-web-forms-handling/
Share on other sites

My form is located at the link below. It doesn't do anything yet as there is no code available to process the form. I have spent some time looking for examples and I see that there are many but of course, they don't meet my needs and require editing. My main question is if PHP is the solution by today's standards.

 

http://www.tallfirshoa.com/adform.htm

 

<?php 
if(isset($_POST['submit'])) { 
$to = "[email protected]";
$subject = "Your subject"; 
$fname = $_POST['fname']; 
$lname = $_POST['lname']; 
$email = $_POST['email'];
$displayemail = $_POST['displayemail']; 
$phone = $_POST['phone']; 
$category = $_POST['category']; 
$description = $_POST['description']; 
$headers = "From: $email \r\n 
            Reply-To: $email";
   
$body = "From: $fname $lname\n E-mail: $email\n Display Email on website: $displayemail\n Phone: $phone\n Category: $category\n Description:\n $description"; 

echo "Dear $fname $lname, <br/> Your Information<br/> E-mail: $email, <br/> Display Email on website: $displayemail, <br/>Phone: $phone, <br/>Categoty: $category, <br/>Description: $description <br/><br/> has been submitted successfully to us!"; 
mail($to, $subject, $body, $headers);
} else { 
echo "Error!";
} 

?>

Well, I wasn't really asking you to code this for me but thank you so much! I can easily see now how this is done. I just found it very confusing with the HTML intermixed with the PHP code. I'm obviously not a PHP developer but I do write code in other languages.

 

Thanks again!

 

Rob

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.