How to use the cakePHP built-in FORM helper to generate Text and Hidden text boxes
I am using cakePHP 1.26. I am sorry to ask this question, but I couldn't work out how to开发者_StackOverflow中文版 use the cakePHP built-in FORM helper to generate the code like these two:
<input type="text" name="data[Test][quote]" id="data[Test][quote]" size="12" style="font-family:Arial" value="helloworld" readonly>
<input type="hidden" name="data[Test][quote]" id="data[Test][quote]" value="helloworld">
Could you help me please?
Try this:
<?php
echo $form->input( 'Test.quote', array( 'type' => 'hidden', 'value' => 'helloworld' ) );
echo $form->input( 'Test.quote', array( 'type' => text', 'size' => 12, 'style' => 'font-family:Arial', 'value' => 'helloworld', 'readonly' => 'readonly' ) );
?>
If you're putting them both on the same page, with the same name, make sure to put the hidden input before the text. That way the text input will override the hidden input if someone enters something in the field.
精彩评论