Forums

number zero made me stuck on server side validation

nilubon03 22 Jun, 2015
Hello,

I do not know what I did wrong with the custom server side validation. One of my field is a text box to allow user enters Number of conference attended in a previous year.

If I enter 3, it passed a validation. If I enter 0, I always get 'Please enter number of conference attended in previous year'. Please see my code below.

Please advise,

Thank you,

Nilubon



$conferenceattended =& trim(strip_tags($form->data['ConferenceAttended']));


$regexconferenceattended = '/^[0-9]{1,3}$/';


if ( !$conferenceattended) {
  $form->validation_errors['ConferenceAttended'] = 'Please enter number of conferences attended in previous year';
  $error_count++;
}else {
  if ( preg_match($regexconferenceattended, $conferenceattended) === 0 )  {
       $form->validation_errors['ConferenceAttended'] = "Please enter number only.";
        $error_count++;
   } else {
      // pass validation, then sanitize input
   	  $conferenceattended_san = filter_var($conferenceattended, FILTER_SANITIZE_SPECIAL_CHARS);
	  
	  //put value back to $form->data, so chronoforms can insert into database 
	  $form->data['ConferenceAttended'] = $conferenceattended_san;

   }
}
GreyHead 23 Jun, 2015
Hi Nilubon,

Please try changing this line
if ( !$conferenceattended) {
to
if ( empty($conferenceattended) ) {

Bob
nilubon03 23 Jun, 2015
Bob,

It did not work. I am still getting 'Please enter number of conference attended in previous year'.

I checked the field name and all the variable, those are correct. What else can I check?
Thank you,
Nilubon
nilubon03 23 Jun, 2015
1 Likes
Hi Bob,

Another tried, I changed to

if ( $conferenceattended == '') {

and it worked.

Thank you for your time.
Nilubon
This topic is locked and no more replies can be posted.