Tuesday, June 3, 2014

Form field which is displayed only

I'm using CakePHP 2.4.9
In my application I want to have a readonly field where I display data which cannot be changed. E.g., a persons country: there is a hidden field with the country ID and a readonly text field with the countries name. The user can see the persons country but is not able to change it. So I do in the edit.ctp


$this->Form->input('Person.country_id', array('type' => 'hidden', ...));

$this->Form->input(null, array('type' => text, 'value' => 'Country', 'readonly' => 'readonly', ...)

The expected outcome is that only the data of the hidden field are posted on submit but not the data of the readonly field.

But what I have is that both fields have the name '[Person][country_id]' and both fields are part of the submit data.

Is there a way to format such informative readonly fields like any other form data, but not include them in the form data on submit?

In the FormHelper I see that the setEntity does not change _entityPath if the $fieldName parameter is null, it just remains what it was before. Is that intended?

I can, of course, use an invalid model. e.g.

$this->Form->input('Invalid.country', ...)

But that looks like an ugly hack to me.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: