user697110
user697110

Reputation: 589

Cakephp form not submitting

I am trying to make a test form in a view I have. So far I have only very simple fields to test if everything is working right (it's not)

$this->Form->create('user', array('url'=>array('controller'=>'users', 'type' => 'post', 'action'=>'add')));
echo $this->Form->input('username');
echo $this->Form->end(__('Submit', true));

Now this prints the submit button and I would assume when it clicked it, it would call the "add" function in my UsersController.php file.

However I have something like this in the controller file

 class UsersController extends AppController {
     .......

public function add() {
 if ($this->request->is('post')) { 
   debug(TEST); die;
   $this->User->create();
   if ($this->User->save($this->request->data)) {
     $this->Session->setFlash(__('The user has been saved'));
     $this->redirect(array('action' => 'index'));
  } else {
  $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
 }}}

  ........

}

Note the debug there and die there, when I submit the debug doesn't print TEST and nothing happens on the page so I assume my form is not submitting properly. I honestly have no idea why, I have been basing my approach in the solutions found here How to submit form for one model in another's controller?

Upvotes: 4

Views: 2739

Answers (1)

user697110
user697110

Reputation: 589

Found the solution, was stuck for hours because an echo was missing before creating the form, I thought those were only supposed to print stuff. I feel utterly terrible

Upvotes: 4

Related Questions