Yii Framework Forum: CHtml::beginForm() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

CHtml::beginForm() Rate Topic: -----

#1 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 03 April 2009 - 08:06 AM

hello,

about this CHtml::beginForm();

I am trying use the search example from Qiang;
using the $_GET vars, but when change the fom submit method, from default post to GET, have one issue;



<?php echo CHtml::beginForm([??????????],'get'); ?>


when put get
beginForm('','get');
form is posting to root web server;

any ideias about get the current url to put here?

<?php echo CHtml::beginForm(Yii:CPagination::getCurrentPage(),'get'); ?>

not work...


why by default not use in this function
beginForm(['post' or 'get' by defaul 'post'],action,options)?

public static string form(mixed $action='', string $method='post', array $htmlOptions=array ( )) 


:)
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 April 2009 - 08:12 AM

Use '' should be fine. Internally, it would be translated to Yii::app()->getRequest()->getUrl()

Note, when you are using GET method, the GET parameters in the action URL are ignored (by HTTP spec). So you may need to put them into hidden fields.
0

#3 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 03 April 2009 - 09:34 AM

mmm not sucess:
current url:

/index.php?r=admin/user/search

form:

<?php echo CHtml::beginForm(Yii::app()->getRequest()->getUrl(),'GET'); ?>
<input type="text" name="kw" value="" autocomplete="off">
<?php echo CHtml::submitButton('search'); ?>
<?php echo CHtml::endForm(); ?>


after submit:


/index.php?kw=teste&yt0=search


what I doing wrong :(

0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 April 2009 - 09:41 AM

As I said, the GET parameters in the URL will be discarded. You need to add a hidden field to store the 'r' parameter.
0

#5 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 03 April 2009 - 09:45 AM

sorry...

working now..!

<input type="hidden" name="r" value="admin/user/search">


the url is now:

/index.php?r=admin%2Fuser%2Fsearch&kw=teste&yt0=Search


thats is good?




0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 April 2009 - 10:01 AM

Yes.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users