Yii Framework Forum: Using Chtml::link with Post parameters - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using Chtml::link with Post parameters how to use Chtml::link with Post parameters?? Rate Topic: -----

#1 User is offline   Pravin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 17-February 11

Posted 12 May 2011 - 03:48 AM

hi there,

Can somebody tell me how to pass parameters with the Post method through a link??
0

#2 User is offline   genn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 23-December 10

Posted 12 May 2011 - 04:22 AM

You create a form and put there some hidden fields. Then set the names/values of the hidden fields to represent the parameters you want to pass.
You also need to assign an id to the link and add a click event.
When the user clicks, you submit the form.
This also allows you to change the parameters at runtime.
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 12 May 2011 - 04:54 AM

Create the link like that:

Chtml::link(
   'label', 
    '', 
    array(
         'submit'=>array('url to submit to'), 
         'params'=>array('parameters to be sent via post')
    )
);


This method will do the same stuff suggested by genn (creating hidden fields with js and then submitting them)
1

#4 User is offline   Pravin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 17-February 11

Posted 12 May 2011 - 06:32 AM

View Postzaccaria, on 12 May 2011 - 04:54 AM, said:

Create the link like that:

Chtml::link(
   'label', 
    '', 
    array(
         'submit'=>array('url to submit to'), 
         'params'=>array('parameters to be sent via post')
    )
);


This method will do the same stuff suggested by genn (creating hidden fields with js and then submitting them)





CHtml::link(
'label',
'',
array(
'submit'=>array('controller/action'), 
'params'=>array('param1' => $data['id1'], 'param2' => $data['id2'])
)
);


I am trying this but nothing happens. And does the second parameter in the Chtml::link has to be empty single quote??
1

#5 User is offline   Jelle Fresen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 16-September 11

Posted 16 September 2011 - 05:03 AM

For general reference

I believe, that the second parameter is the url that is displayed by the browser in the statusbar (at least, in Firefox). The submit url in the htmlOptions array is the url where the link will actually take you to. For a good user experience, you should set these to the same value, e.g.

$url = array('controller/action');
CHtml::link(
	'label',
	$url,
	array(
		'submit' => $url,
		'params' => array('param1' => $data['id1'], 'param2' => $data['id2']),
	)
);

2

#6 User is offline   PrgCoder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 26-June 13
  • Location:Sydney

Posted 26 June 2013 - 07:02 PM

Can someone please show some sample code of what you would have in your controller to access/read these parameters.

Would it look like:

    public function actionMyAction() {
        $param1 = Yii::app()->request->getPost('param1');
        $param2 = Yii::app()->request->getPost('param2');

        $this->render('newView', array(
            'param1' => $param1,
            'param2' => $param2,
        ));
    }


I can not seem to access the POST values.

Regards,
Andy.
1

#7 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 515
  • Joined: 08-August 09

Posted 26 June 2013 - 11:30 PM

Yes, you're calling them correctly. I'd check $_POST directly, most probably it's empty if you don't get your parameters.
References to documentation related to this thread:
CHtml.link() Submit and params attributes

CHtml.link()

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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