happyhardik
happyhardik

Reputation: 25527

Cakephp just display a form field without input

I am using CakePHP. I have a form, let's say user profile edit, and I don't want the user to modify the username, but I still want to display it.

I am displaying it using something like:

echo $this->Form->input("username");

This outputs a label named Username and an input text box. I don't want this text box, instead just want another label with the username value.

Have been going through the cook book, but can't find it.

Upvotes: 1

Views: 2524

Answers (2)

Dave
Dave

Reputation: 29121

You can literally just make an HTML label, and use the value that's passed:

<label for="username">Username:</label><?php echo $this->data['User']['username']; ?>

Upvotes: 1

JJJ
JJJ

Reputation: 33163

The value is stored in $this->data[ 'User' ][ 'username' ] (assuming the model's name is "User").

On the other hand if you want to just disable the edit box, use this:

echo $this->Form->input(
    'username',
    array( 'disabled' => 'disabled' )
);

Upvotes: 4

Related Questions