|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
PHP -- Form Submit
Ok guys i have this for the displays the errors if the 3 feilds are incorrect, what i need ot todo is keep the form fields in view and just report the error's above each field ie if u have entered an incorrect email address etc, hope this makes sence and someone can help..
Cheers Code:
<?php
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
$errors = array(); // Initialize error array.
// Check for a name.
if (empty($_POST['name'])) {
$errors[] = 'You forgot to enter your name.';
}
// Check for an email address.
if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
$errors[] = 'You forgot to enter a valid email address.';
}
// Check for a company.
if (empty($_POST['company'])) {
$errors[] = 'You forgot to enter your organisation/company.';
}
if (empty($errors)) { // If everything's okay.
// Send an email.
$body = "Thank you for Signing up to receive latest news and details";
mail ($_POST['email'], 'e-newsletter confirmation!', $body, 'From: mymail@myurl.com');
echo '<p>Thank you for Signing up to receive latest news and details</p><p><br /></p>';
} else { // Report the errors.
echo '<strong>Error</strong>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please click the back and try again.</p><p><br /></p>';
} // End of if (empty($errors)) IF.
} else { // Display the form.
?>
Please Fill out the form below and click submit<br /><br />
<form action="enews.php" method="post">
<p>Name: <input type="text" name="name" size="20" maxlength="40" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="40" /> </p>
<p>organisation/company: <input type="text" name="company" size="10" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
} // Close the main IF-ELSE.
?>
__________________
Practice safe design all ways use a concept. If I have been helpful please click the scales. Last edited by Sluap : February 24th, 2006 at 11:11 AM. |
|
#2
|
|||
|
|||
|
When you display the form, check for an error for each field and display it if it exists.
So, the easiest way is to give the error message a key depending on the field it belongs to. PHP Code:
& AspFree's sister site forums.devshed.com is a better place to ask php questions. --Simon |
|
#3
|
||||
|
||||
|
Quote:
thx yes i have registered over there now, cheers ill give this ago |
|
#4
|
||||
|
||||
|
you can always pm me php questions here too
B&W does ![]()
__________________
|
|
#5
|
||||
|
||||
|
Why PM them? Post them here for others to see/help...
__________________
Support requests via PM will be ignored! |
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
||||
|
||||
|
I didn't even realise PHP questions got asked in here, so I never even
visited this forum. I will from now on though, and I should hopefully be added as a mod in here any time now... ![]() |
|
#8
|
||||
|
||||
|
Quote:
|
|
#9
|
||||
|
||||
|
Was waiting for u to get on MSN RF but i belive you have been away?? i sorted it now but im only on page 210 of a 667 page book so be warned im going to have many questions fireing your way heehee.
Cool Cheif u know Php aswel thats 1 more to pester ![]() |
|
#10
|
||||
|
||||
|
Quote:
|
|
#11
|
||||
|
||||
|
Quote:
You could just subscribe to this forum! That way you'll get an email when a new thread is created. ![]() |
|
#12
|
||
|
|