Forums

Simple Text box 'word' validation

olaeblue 12 Sep, 2011
I am using Chronoforms 4 RC2.0 in J1.7

I want to get people to write 'For' 'Against' or 'Abstain' in a text box & then check that they have only written that before accepting the form and going on to email them.
I don't want a check box or drop down as I want them to type the word. Any advice?
I am reasonably proficient at VB & C so should be able to work out the structure I need for any coding if i could only get a prompt of how I get the textbox content and how I allow or prevent 'submission'.

Sorry if this is a bit 'micky mouse' but I am trying to learn :-)

Thanks
olaeblue 14 Sep, 2011
Just for completeness I solved this myself. Was obvious really!🤣

Custom server side validation on submit with code

<?php
$error_count = 0;
$response = $form->data['response'];

if ((strtolower(trim($response))=="for")||(strtolower(trim($response))=="against")||(strtolower(trim($response))=="abstain"))  {

} else {
     $error_count++;
     $form->validation_errors['response'] = "Must be For, Against or abstain";
}
if ( $error_count ) {
  return false;
}

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