[Yii Framework] Form with GET method

All the content of this article only happend in Yii Framework!

 

As we know, with a form, we can both use post and get to send the data. But in Yii, when creating a form as below: 

<?php echo CHtml::beginForm('user/index','get'); ?>
  <?php echo CHtml::label('User','user01',array('class'=>'small'))?>
  <?php echo CHtml::textField('search','',array('id'=>'user01','class'=>'sText'))?>
  <?php echo CHtml::submitButton('Search',array('class'=>'butDef')); ?>
<?php echo CHtml::endForm(); ?>

after submited the form, we get nothing of the $_GET data! (except that we can get "r='user/index'").

but why, this form seems everything ok!

Then via google, i found the reason:

A GET form action cannot include query parameters. You need to use hidden variables to generate the query paramaters. 

here is the way to resolve it, add the code to the form:

<?php echo CHtml::hiddenField('r','user/index')?>

 

Have fun with Yii! 

 

posted @ 2012-10-15 10:10 DavidHHuan 阅读(...) 评论(...) 编辑 收藏