I appreciate your help very much... but what about all the database stuff? The SQL? This needs to be stored in a db. The table is already built.arborint wrote:Forms processing is just complex enough that it is difficult for beginners to do, and difficult for experienced programmers to generalize (or at least agree on how to do it).milane wrote:Like I said, I want to do it myself... I work for a nonprofit... ie - we dont have no money.
Not looking for a handout... just a tool I can use to make life easier.
That said the basics are pretty simple. First you need a HTML form, which starts with a form tag that specifies the page that the form will be submitted to and the method (GET or POST). It looks like this:Then there are form fields. There are a couple of different kinds. The basic text input looks like this with a name and a value (which is empty in this example):Code: Select all
<form action="myformpage.php" method="post">Then a button to submit the form:Code: Select all
<input type="text" name="first_name" value=""/>And finally you need to close the form with the tag:Code: Select all
<input type="submit" name="submit" value="Go"/>I am going the add a error message which will come from the PHP script below. The whole thing looks like this (put it in a file named myformtemplate.php):Code: Select all
</form>OK, so that's the HTML part. Now you need the PHP script to manage the form. One way to do it goes something like this:Code: Select all
<span style="color:red"><?php echo implode('', $errors); ?></span> <form action="myformpage.php" method="post"> <input type="text" name="first_name" value=""/> <input type="submit" name="submit" value="Go"/> </form>
1. Get the values from the $_POST superglobal array.
2. Filter the values to make sure there are no unwanted characters
3. Check that required values exist and are valid
4. If there are errors then display the form
5. If there are no errors then redirect to the next page (this prevents resubmits).
So the PHP code would looks something like this (put this code in the file myform.php):To test it go to http://www.mysite.com/myform.phpCode: Select all
// filter the value from the form to only all letters and space $first_name = preg_replace('/[^a-zA-Z\ ]/', '', $_POST['last_name']); // check the name based on some rules and set errors if there are problems $errors = array(); if ($first_name == '') { $errors[] = 'Please enter a first name. '; } elseif (strlen($first_name) < 3) { $errors[] = 'The first name must be at least three letters long. '; } // check if the form is valid if ($errors) { // show the form if there are errors include 'myformtemplate.php'; } else { // do and other processing here, such as saving to a database or emailing mail('me@mysite.com', 'Form Message', "A message from $first_name"); // redirect to another page if all required fields are acceptable header('Location: http://www.mysite.com/mynextpage.php'); }
There are some other things to add like checking for submit and not showing error messages the first time the page is displayed ... but that's the basics.
EDIT - fixed (strlen($first_name) < 3) per Everah
J