php - How to validate user must choose at least one value radio button in CakePHP? -
i have code in view file radio button (cakephp) :
echo $this->form->input('publish_flg', array( 'type' => 'radio', 'div' => false, 'label' => false, 'fieldset' => false, 'legend' => false, 'hiddenfield' => false, 'required' => false, 'separator'=> '</div><div class="radio-inline">', 'before' => '<div class="radio-inline">', 'after' => '</div>', 'options' => array(1 => 'yes', 0=> 'no'), 'error' => array( 'attributes' => array('wrap' => 'div', 'class' => 'alert alert-danger', 'escape' => 'false') ) ));
now want user must check @ least 1 value in radio button, both validate write in model not successfull :
solution 1 (it return message error both check or not check radio button)
public $validate = array( 'publish_flg' => array( 'notempty' => array( 'required' => true, 'message' => 'error validate' ) ) );
solution 2 (it not validate, if don't check radio button, submit data database)
public $validate = array( 'publish_flg' => array( 'rule' => 'notempty', 'message' => 'error validate' ) );
can give me solution ? , thanks.
in controller, don't use $this->model->save() validate, used $this->model->validates(), wrong ?
notempty
validation should work, try inlist
, since specify values either 0
no
, 1
yes
in formhelper
.
if you're not sure syntax, try bake
model , create validation rules way.
Comments
Post a Comment