Saturday, 15 June 2013

php - how to post checkbox to action in Yii? -



php - how to post checkbox to action in Yii? -

i want post checkbox action , print alert if checkbox checked, here code:

view:

echo chtml::checkbox('hi'); echo chtml::button('search', array('onclick' => 'js:document.location.href="index"'));

controller:

public function actionindex() { $model = jobs::model()->findall(); $model2 = tags::model()->findall(); if(isset($_post['hi'])) echo "<script>alert('hello');</script>"; $this->render('index', array('model'=>$model, 'model2'=>$model2)); }

when check checkbox , click button nil happened, error in code?

you redirect page actionindex. must submit form instead of redirecting it. take look:

echo chtml::beginform(yii::app()->createurl('index'), 'post'); echo chtml::checkbox('hi'); echo chtml::submitbutton('search'); echo chtml::endform();

if try:

cvardumper::dump($_post,56789,true);

you can see post value after submitting form.

or can via java-script in button:

//if have created form echo chtml::button('search', array('onclick' => 'this.submit();'));

php checkbox yii

No comments:

Post a Comment