Alex Rivera | Logout

CakePHP "Agree TOS" Checkbox Validation

Asked 2011-07-16T14:16:26.840
10

I am trying to have a Checkbox "Agree TOS".

If the Checkbox is not checked, I want to put out a Flash Message.

How do I do this?

My View:

<?php   
        echo $form->create('Item', array('url' => array_merge(array('action' => 'find'), $this->params['pass'])));
        echo $form->input('Search', array('div' => false));
        echo $form->submit(__('Search', true), array('div' => false));
        echo $form->checkbox('tos', array('label' => false, 'value'=>1)).' Agree TOS'; 
        echo $form->error('tos');
        echo $form->end();
?>

My Model:

var $check = array(
            'tos' => array(
               'rule' => array('comparison', 'equal to', 1),
               'required' => true,
               'allowEmpty' => false,
               'on' => 'index',
               'message' => 'You have to agree TOS'
               ));
Edit
Report

1 Answer

0

you don't even have to have validation rule for tos, just check that at the controller before saving the data.

if($this->data['Model']['tos']==1){
     // save data
  }else{
     //set flash
  }
answered 2011-07-17T01:16:23.523

Your Answer