I wanted to now if there is a way to pass a simple string inside url and cakephp some how put it inside one of the inputs of my form without any code writing on view side? I tried calling this->set("bla","bla"); the field name is bla but nothing changed in view
+1
A:
You can pass values in the url by using html helper. Try:
echo $this->Html->link('View Some Page', array(
'controller' => 'yourController',
'action' => 'view',
1, // id
'?' => array('yourField' => 'valueToPass'))
);
bancer
2010-10-15 23:06:14
should work for add two(instead of view)?
Chen Kinnrot
2010-10-15 23:22:56
I did not understand your question. If you build a link using html helper you can pass any value of any parameter to any page you want.
bancer
2010-10-15 23:26:02
Yes yes this is obvious, will cake know to put the data in the view field?
Chen Kinnrot
2010-10-15 23:32:21
Try to do that. If it does not work then you will need to catch the value from url in the view (`$this->params['yourField']`) and input it to the field as default value, for example http://book.cakephp.org/view/1402/options-default.
bancer
2010-10-16 00:03:34
A:
As I understood the question you want to have something like this:
in the url you have something like:
http://yourserver.com/controller/action?search=string
and you want to put this "string" in the search field, right?
Then let's imagine that your field's name is data[search_field]. (I am skipping the model, because for my example it's not needed, but it's possible the name to be data[Model][search_field]).
Then in your controller's action you have to do following:
$this->data['search_string'] = $this->params['url']['search'];
Nik
2010-10-16 10:31:48
Only one thing is missing, if form encounters a validation error after submit, this will fire a warning I needed to add the flollowing: if (isset($this->params['url']['subject'])) { echo $form->hidden('subject',array('default'=>$this->params['url']['subject'])); } else { echo $form->hidden('subject'); }
Chen Kinnrot
2010-10-18 18:35:18