[SOLVED] Display multiple server side validation errors

WhiteLighter01 08 Nov, 2011
Hi all,

If I have multiple fields being validated. How can I display all the errors all at once on a continuous list?

Here's what I have so far
<?php
$errors = array();

if ($_POST['subject'] == ''){
	$errors[] = 'Please select a subject below.';
}
if ($_POST['address'] == ''){
	$errors[] = 'Address field is required.';
}

if (count($errors)){
	$errors = implode('<br/>', $errors);
	return $errors;
}
?>


Together with the CAPTCHA error, it displays something like this
1. You have entered an incorrect verification code at the bottom of the form.
2. Please select a subject below.
Address field is required.


How can I display multiple error messages with a continuous number list?

Thanks
GreyHead 08 Nov, 2011
Hi WhiteLighter01,

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6.

Bob
WhiteLighter01 08 Nov, 2011
Sorry, I forgot to mention the version. Its 3.2
GreyHead 09 Nov, 2011
Hi WhiteLighter01,

I'm not sure if you can. This might work:

<?php
$errors = false;
$subject = JRequest::getString('subject', '', 'post');
if ( !$subject) {
  $MyForm->addErrorMsg('Please select a subject below.');
  $errors = true;
}
$address = JRequest::getString('address', '', 'post');
if ( !$address ){
  $MyForm->addErrorMsg('Address field is required.');
  $errors = true;
}
if ( $errors ) {
   return 'Please correct the errors shown here';
}
?>

Bob
WhiteLighter01 10 Nov, 2011
Thanks,

It worked ^_^ I did replaced the colons ":" with a semi-colon ";" :p
GreyHead 10 Nov, 2011
Hi WhiteLighter01 ,

Glad this worked - sorry about my typos :-(

Bob
This topic is locked and no more replies can be posted.