0

i want change the name of the input to make it name=data[Contact][firstname] because I want to display the data when i click edit() i guess that is the reason why it is not displaying. echo $this->Form->input('First Name:', array('class'=>'form-control')); the name of the input is same n the first param. please help

5
  • Maybe you want to change the label of the input? Commented Nov 26, 2015 at 8:58
  • how to add value attribute in a form using cakephp sir? because i have a data i want to put in the input value for edit purpose. Commented Nov 26, 2015 at 9:00
  • 1
    You should read this. Data is passed to the form so inputs should be populated in the edit form. Commented Nov 26, 2015 at 9:05
  • What are you actually trying to do as it is not clear? What is your current code and why exactly do you want to change the name attribute? Commented Nov 26, 2015 at 9:59
  • I set the data i send to edit method in the controller to make it display as a default value for edit purpose sir. Commented Nov 27, 2015 at 1:15

2 Answers 2

1

Your code should be like this:

echo $this->Form->input('firstname', array('class'=>'form-control','label'=>'First Name'));
Sign up to request clarification or add additional context in comments.

2 Comments

sir i followed this. But still I can't display the data i set in the controller to display as the default value of inputs when edit button is click.
i set a value property to the data from the data echo $this->Form->input('firstname', array('class'=>'form-control', 'label'=>'First Name:', 'default'=>$contact['Contact']['firstname'])); to make it as a default value. And now i am able to edit the current data. Thank you sir!
1

The first parameter is the name of the input field (name="firstname"). It is not the label (First name: ). so your code should be,

$this->Form->input('firstname', array('class'=>'form-control'));

To get this structure [Contact][firstname], your form name should be 'contact'.

$this->Form->create('Contact',array('class'=>'form'));
    $this->Form->input('firstname', array('class'=>'form-control'));

2 Comments

sir i followed this. But still I can't display the data i set in the controller to display as the default value of inputs when edit button is click.
i set a value property to the data from the data echo $this->Form->input('firstname', array('class'=>'form-control', 'label'=>'First Name:', 'default'=>$contact['Contact']['firstname'])); to make it as a default value. And now i am able to edit the current data. Thank you sir!

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.