0

I have the below formhelper code where $spot is an array of variables:

   echo $form->create('Spot', array('controller' => 'spots', 'action' => 'view'));
                    echo $form->hidden('spotdata', array('value' => $spot));
                    echo $form->end('View');

When I print_r($this->data) in my controller, the spotdata is empty. Can the formhelper accept values that are arrays? Is there any way to do this? Please let me know, thanks!

3 Answers 3

1

I notice you are sending the data to a view. It's more idiomatic to just send the ID to the view, and the data can be reloaded from the database. In which case a link would be enough:

echo $this->Html->link('View', 
    array('controller' => 'spots', 'action' => 'view', $spot['Spot']['id']));

If you are trying to keep the state between pages you may find it easier and more secure to use the SessionComponent to do this (never trust data sent back from the client). In your controller method, this is as easy as:

$this->Session->write('Spot.spotData', $spot);

and

$spot = $this->Session->read('Spot.spotData');

to read back the data.

Sign up to request clarification or add additional context in comments.

Comments

1

No, since it echoes an HTML input tag. The value has to be a string or something that can be cast as a string. View your HTML source.

1 Comment

k thanks. i just looped through and echo'd each key => value as a hidden input
0

Instead of looping through the array and echo'ing each key, you can also serialize() the array and place it in a single hidden input. Afterwards you can deserialize() it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.