Thursday, December 30, 2010

Re: post form data from URL

On Thu, Dec 30, 2010 at 2:25 PM, Steve Mallett <steve.mallett@gmail.com> wrote:
> Sorry, I'm still up in the air with this...
>
> <?php echo Router::url($this->here, true); ?>  echos
> localhost/links/add/cakephp.org if I type
> "localhost/links/add/cakephp.org" as the URL. How do I pass just
> 'cakephp.org' to the form?

Do you really need to include that in the URL anyway? Could you just
present an empty form and have the user fill it in?


> To confuse things I got looking more at
> http://book.cakephp.org/view/945/Routes-Configuration#Passing-parameters-to-action-949...
>
> Perhaps this is good?:
> function add() {
>   Router::url('links/add/:url',array('controller' => 'links',
> 'action' => 'add'), array('pass' => array('url')));
> }

Good for what? Router::url() returns a string.You're not echoing nor
assigning the return value to anything.


> I'm still confused on how 'pass' 'url' to the form.

First, get passing it to the controller action sorted out. Then you
can assign it to a view variable and pass that to FormHelper.

Start with the route:

Router::connect(
'/links/add/:url',
array(
'controller' => 'links',
'action' => 'add'
),
array(
'url' => '^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$',
'pass' => array('url')
)
);

You may need to adjust the regexp to suit your requirements.


public function add($url = null)
{
if (!empty($this->data))
{
...
}

$this->set(compact('url'));
}


echo $this->Form->input('Link.url', array('value' => $url));

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: