...

View Full Version : Form processing



Saz
09-17-2005, 07:25 PM
Can anyone help on any of the below bits for a form completion please?

What code would you use to ensure the submitter includes the @ sign in
the email field?

What code would you use to ensure the submitter only used numerals in a telephone field?

As an extra to us getting a copy of the forms contents - how do we get a copy of the form's contents sent by email to the submitter, with a little message from the webmaster.

Any help appreciated.

Saz.

marek_mar
09-17-2005, 08:41 PM
ctype (http://www.php.net/ctype) functions.

Saz
09-17-2005, 09:52 PM
Any help appreciated.

matthijs
09-17-2005, 10:06 PM
Hi Saz, just a quick reply: a good tutorial here:
form processing (http://www.apptools.com/phptools/forms/)
and http://www.developer.com/lang/php/article.php/3468701 and many others places. Just read some basic tutorial on a good programming site.

Saz
09-18-2005, 09:39 AM
Many thanks Marek and Matt for the links. I must admit, I've only been into PHP for a little while, so most of the terminology is way over my head, but will keep trying.

On one of those links, I saw the code for the numerals part, but nothing for the other 2 questions:

What code would you use to ensure the submitter only used numerals in a telephone field?

What code would you use to ensure the submitter includes the @ sign in
the email field?

As an extra to us getting a copy of the forms contents - how do we get a copy of the form's contents sent by email to the submitter, with a little message from the webmaster.

Any help appreciated.

Saz.

facets
09-18-2005, 10:03 AM
I guess we may need to see some code to debug and find out why your address isn't coming through correctly??

Saz
09-18-2005, 10:16 AM
Sorry, I should have done that before - any help would be really appreciated:


<? ob_start(); ?>
<HTML>
<HEAD>
<TITLE>Form processing with PHP</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">


<?

// Check to see if the form has been submitted
if ($_GET["submit"])
{

// Assign 0 to the error variable
$Error = 0;

// Let's extract the GET form field elements
extract($_GET);

// Now, we'll check to see if ANY of the form elements are blank
if (!($name) || !($email) || !($subject) || !($message))
{
// at least one of the form fields are blank
if (!($name))
{
$Error = 1;
$ErrorName = 1;
}

if (!($email))
{
$Error = 1;
$ErrorEmail = 1;
}

if (!($subject))
{
$Error = 1;
$ErrorSubject = 1;
}

if (!($message))
{
$Error = 1;
$ErrorMessage = 1;
}

} else {

// all the form fields are filled in with data

// email the data to an email address
$To = "test@010805.com";
$Subject = "Form submission";
$Message = "Name: $name \nEmail: $email \nSubject: $subject \nMessage: $message";
mail($To, $Subject, $Message, "From: Your@Email.com");

// redirect to the thank you page
header("Location: http://www.010805.com/enquiries-1/thanks.html");

}

}
?>

<? if ($Error > 0)
{
// Instruct the user that an error is present
echo "<strong>Oops, you did not fill out all required fields. Those fields are marked below.</strong> <br />";
}
?>

<form action="index.php" method="GET">
<table width="100%">
<tr><td align="left" width="11%">
<? if (($Error == 1) && ($ErrorName == 1)) { echo "<font color=\"Red\">*</font>"; } ?>
Your Name:</td>
<td align="left" width="87%"><input type="text" name="name" size="26" value="<? echo $name; ?>"></td></tr>
<tr><td align="left" width="11%">
<? if (($Error == 1) && ($ErrorEmail == 1)) { echo "<font color=\"Red\">*</font>"; } ?>
Your E-mail:</td>
<td align="left" width="87%"><input type="text" name="email" size="26" value="<? echo $email; ?>"></td></tr>
<tr><td align="left" width="11%">
<? if (($Error == 1) && ($ErrorSubject == 1)) { echo "<font color=\"Red\">*</font>"; } ?> Subject:</td>
<td align="left" width="87%"><input type="text" name="subject" size="26" value="<? echo $subject; ?>"></td></tr>
<tr><td align="left" width="11%" valign="top">
<? if (($Error == 1) && ($ErrorMessage == 1)) { echo "<font color=\"Red\">*</font>"; } ?>
Message:</td>
<td align="left" width="87%">
<p align="left"><textarea cols="34" rows="4" name="message"><? echo $message; ?></textarea></p>
<p align="left"><input type="submit" name="submit" value="Send Mail">&nbsp;&nbsp;
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>

</BODY>
</HTML>
<? ob_flush(); ?>

Saz
09-18-2005, 12:52 PM
Ooooops, just had a thought - some people might also use letters and spaces in the telephone field, so is there any php code that won't let the form submit, unless there's at least 5 numerals please?

Any help much appreciated.

Saz.

marek_mar
09-18-2005, 02:56 PM
Everything more complex that the ctype functions will probably require the use of regular expressions (http://www.php.net/manual/en/reference.pcre.pattern.syntax.php). (I suggest using something else as a tutorial though).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum