Hi there!
Below the code i'm using in my chronoform component. It shows the form correctly. But when i test the form not filling in any information it shows the form again but doesn't show the error messages and stil sends an email?
form HTML:
On submit code - before sending email:
Any help is appreciated!
Thnx guys
Raymon
Below the code i'm using in my chronoform component. It shows the form correctly. But when i test the form not filling in any information it shows the form again but doesn't show the error messages and stil sends an email?
form HTML:
<?php
if ($errorName) $errorTextName = "Please enter your name!";
if ($errorEmail) $errorTextEmail = "Please enter a valid email address!";
if ($errorMesg) $errorTextMesg = "Please leave a longer message!";
// Display name field an error if needed
echo '<tr><td>Name:</td><td><input type="text" name="name"></td></tr>';
if ($errorName) echo "<tr><td colspan='2'>$errorTextName</td></tr>";
// Display email field an error if needed
echo '<tr><td>Email:</td><td><input type="text" name="email"></td></tr>';
if ($errorEmail) echo "<tr><td colspan='2'>$errorTextEmail</td></tr>";
// Display message field an error if needed
echo '<tr><td>Message:</td><td><textarea name="mesg"></textarea></td></tr>';
if ($errorMesg) echo "<tr><td colspan='2'>$errorTextMesg</td></tr>";
echo '<tr><td><input type="submit" name="SubmitForm" value="Send"></td></tr>';
?>
On submit code - before sending email:
<?php
if (!isset($_POST['SubmitForm'])) {
showForm();
} else {
//Init error variables
$errorName = false;
$errorEmail = false;
$errorMesg = false;
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$mesg = isset($_POST['mesg']) ? trim($_POST['mesg']) : '';
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) $errorEmail = true;
if (strlen($name)<3) $errorName = true;
if (strlen($mesg)<10) $errorMesg = true;
// Display the form again as there was an error
if ($errorName || $errorEmail || $errorMesg) {
showForm($errorName,$errorEmail,$errorMesg);
} else {
echo 'Submission was success!';
}
}
?>
Any help is appreciated!
Thnx guys
Raymon
Hi Raymon,
Your main problem is that you'll need to find a way to pass your error messages back through showForm().
showForm() only takes one parameter (you're sending three), and, at the moment does nothing with it.
I think that you'll need to pack your error messages into a single array variable; add $posted to the HTML_ChronoContact::showform( $rows , $imver); call in chronocontact.php and to the corresponding function in chronocontact.html.php; lastly declare it as a global in the form code and unpack it there.
Bob<br><br>Post edited by: GreyHead, at: 2008/03/05 12:51
Your main problem is that you'll need to find a way to pass your error messages back through showForm().
showForm() only takes one parameter (you're sending three), and, at the moment does nothing with it.
I think that you'll need to pack your error messages into a single array variable; add $posted to the HTML_ChronoContact::showform( $rows , $imver); call in chronocontact.php and to the corresponding function in chronocontact.html.php; lastly declare it as a global in the form code and unpack it there.
Bob<br><br>Post edited by: GreyHead, at: 2008/03/05 12:51
This topic is locked and no more replies can be posted.