A CakePHP readonly text field

CakePHP readonly text field FAQ: Can I make a readonly textfield in CakePHP (a CakePHP Form input field, or Form text field)?

I haven't worked it all out yet, but I first tried to create a CakePHP readonly text field like this, using the CakePHP Form text object, which doesn't seem to work:

# this doesn't work
echo $this->Form->text('complexity', array('readonly' => 'readonly'));

When that failed I kept poking on the CakePHP Form input object, and was able to create a readonly text field like this:

# this is working
echo $this->Form->input('complexity', array('type' => 'text',
                                            'readonly' => 'readonly'));

As mentioned, I still haven't figured out all the magic here, but this does seem to be working, so I thought I'd share this solution here. This is currently working in my CakePHP 1.3.6 project, though I can't find this "readonly" reference in the 1.3.x docs. (I'm sure I could probably do this with some CakePHP jQuery mojo, but making the field readonly through HTML seems like a much better approach to me.)

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.