Found this form validation code in a legacy PHP project:
if( $this->GetPreference('selfreg_force_email_twice') ) { if( !isset($params[$email_field.'_again'] ) ) { // $params['error'] = 1; // $params['message'] = $this->Lang('error_nosecondemailaddress'); // $this->myRedirect( $id, 'default', $returnid, $params ); // return; if (strlen($errors)>0) $errors .= '~'; $errors .= $this->Lang('error_nosecondemailaddress'); }if( $params[$email_field] != $params[$email_field.'_again'] ) {
// $params['error'] = 1;
// $params['message'] = $this->Lang('error_emaildoesnotmatch');
// $this->myRedirect( $id, 'default', $returnid, $params );
// return;
if (strlen($errors)>0)
$errors .= '~';
$errors .= $this->Lang('error_maildoesnotmatch');
}
}
This same thing happens another 35 times in the script. If the error string isn't empty, append a tilde character, then append the error message.
And yes, the formatting is verbitem, here's a more interesting example:
// check for required parameters if( !isset( $params['group_id'] ) ) { $this->_DisplayErrorPage( $id, $params, $returnid, $this->Lang('error_insufficientparams')); return; }// Check to ensure all required fields have some content // and validate email fields //go through each paramter foreach( $params as $key => $val ) { //make sure the param is a hidden field (cause it has all the details in it in a ';' seperated list) if( preg_match( '/^hidden_/', $key )) { $propname = substr($key,strlen('hidden_')); $arr = split(";",$params[$key]); $required = $arr[3]; //if the field is required and is empty, throw an error if( $required == 2 && (!isset($params['input_'.$propname]) || $params['input_'.$propname] == '' )) {
// $params['error'] = 1;
// $params['message'] = $this->Lang('error_requiredfield',$propname);
// $this->myRedirect( $id, 'default', $returnid, $params );
if (strlen($errors)>0)
$errors .= '~';
$errors .= $this->Lang('error_requiredfield',$propname);
}//this is an email address and needs to be validated as such if( $propname == 'email_address' ) { $result = $feusers->IsValidEmailAddress( $params['input_'.$propname], $feusers->GetPreference('do_smtp_validate_email') ); if( $result[0] == false ) {
// $params['error'] = 1;
// $params['message'] = $result[1];
// $this->myRedirect( $id, 'default', $returnid, $params );
if (strlen($errors)>0)
$errors .= '~';
$errors .= $result[1];
} //end validate email check
} //end validate email
} //end if hidden
} //end foreach