Web forms, how hard can they be?

Web forms, how hard can they be?

For me bloody hard going. Not so much the html & css but th ephp behind it to get the relevant info pinged back into your eMail.

This post is going to be therapy for me you habe been warned.

All i wanted to do was get the info on this form:
http://www.pauserefreshment.co.uk/coffee-machine-brochure-request.html
to ping back the data to my inbox.

I started lookin at sitepoints book “Fancy form Design” but this book does not give any useful php info regarding how your supposed to get the info pinged back to your eMail once youve designed your fancy form, a missing chapter i think!

I then took a look at O’reilly’s “Head first PHP & MySQL”. From this there was actual code you could use for a form. I used this and had some success, i could get info eMailed to me but the echo stuff i could just not change and caused lots of headaches :mad:

Ant (sitepoint member) has helped me out but my lack of understanding has caused balls ups.

So is there a tutorial or book that teaches you not only how to design forms but gives full insight into the php scripts that run behind them so people like me can start to figure it all out.

I’ve found it so hard getting a useful / idiots guide to php scripts for web forms. Can anyone point me in the right direction?

<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aliens Abducted Me - Report an Abduction</title>
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2>
<?php
ini_set("sendmail_from", "user@yourdomain.com"); 


if (empty($_SERVER['HTTP_REFERER']) || (
	(!strstr($_SERVER['HTTP_REFERER'], "http://dev.spookmedia.com/")) &&
	(!strstr($_SERVER['HTTP_REFERER'], "http://pause.zippy.sdev.net/")) &&
	(!strstr($_SERVER['HTTP_REFERER'], "http://www.pause.co.uk/"))&&
	(!strstr($_SERVER['HTTP_REFERER'], "http://www.pauserefreshment.co.uk/"))&&
	(!strstr($_SERVER['HTTP_REFERER'], "http://www.refreshments.co.uk/"))
   ))
{
	header("HTTP/1.0 404 Not Found");
	return;
}

  $name = $_POST['name'] . ' ' . $_POST['secondname'];
  $when_it_happened = $_POST['whenithappened'];
  $how_long = $_POST['email'];
  $how_many = $_POST['company'];
  $alien_description = $_POST['address'];
  $what_they_did = $_POST['address2'];
  $fang_spotted = $_POST['postcode'];
  $email = $_POST['email'];
  $other = $_POST['city'];
  
 
  $to = 'hello@pause.co.uk';
  $subject = 'Aliens Abducted Me - Abduction Report';
  $msg = "$name was abducted $when_it_happened and was gone for $how_long.\
" .
    "Number of aliens: $how_many\
" .
    "Address: $alien_description\
" .
    "What they did: $what_they_did\
" .
    "Fang spotted: $fang_spotted\
" .
    "Other comments: $other";
  mail($to, $subject, $msg, 'From:' . $email);

  echo 'Thanks for submitting the form.<br />';
  echo 'You were abducted ' . $when_it_happened;
  echo ' and were gone for ' . $how_long . '<br />';
  echo 'Number of aliens: ' . $how_many . '<br />';
  echo 'Describe them: ' . $alien_description . '<br />';
  echo 'The aliens did this: ' . $what_they_did . '<br />';
  echo 'Was Fang there? ' . $fang_spotted . '<br />';
  echo 'City: ' . $other . '<br />';
  echo 'Your email address is ' . $email . '<br />';
  ?>
</body>
</html>


Its amazing what a good nights sleep can do. Ive finally got the web form pinging back all the info I want using php.

I went back to the O@reilly book php & mySql head first chapter 1 and got my head around $_POST with their cup analogy and the penny dropped.

This case is now: Closed

Thanks soonerdm your post is very helpful. I just wonder however is there a tutorial or book to break this stuff down from a total beginners standpoint. This stuff is a second language to the php enlightened but to me its swahili.

I’ve roamed google land and nothing does it for me :confused:

Web Forms and PHP are two different things.

A web form is simply the way things are laid out or called the front end. The mailer or processing of the form is the backend. What you are wanting to do is process the form using PHP. Forms are the foundation for Web Applications so understanding how to process them is fundimental in development.

Whatever you set your form method to is how you get your varibles

<form method=‘POST’
or
<form method=‘GET’

your varibles are the values of the form fields… usually user input
<input type=text name=‘this_varible’ value=‘’>

so if that text field was your only field in your form and the method attribute was set to POST your varible would be $_POST[‘this_varible’]

You would then use it in the script your action attirbute was set to in the form tag

in your case you want to mail so…

mail(‘youremail@domain.com’, ‘This is the Subject’, $_POST[‘this_varible’]);

That would send an email to youremail@domain.com with a subject of This is the Subject and in the body it would be what the value of the $_POST[‘this_varible’]