0

Is it possible to create such a form:

<form id="xxx" method="post" action="">

via CakePHP:

echo $this->Form->create('xxx');

?

If it is, please, tell me how.

Filip Frątczak
  • 137
  • 1
  • 3
  • 14

1 Answers1

1
echo $this->Form->create(false, ['id' => 'xxx', 'url' => '/' . $this->params['url']['url']]);

should achieve what you need.

Though the question is why do you need action to be empty string? Setting action attribute as empty string would POST the form to current url and by default FormHelper::create() already set the action attribute to current url.

ADmad
  • 8,102
  • 16
  • 18
  • This statement: `create(false, ['id' => 'xxx', 'url' => '']);?>` redirects me to `/xxx/add`. I'm using cakephp 1.2. Maybe that's the problem. Also, it works if in my view I'm using
    tak insted, but then I cannot validate errors.
    – Filip Frątczak Sep 26 '14 at 07:24
  • Ah yes 1.2 was a bit silly in how it inferred and generated form urls. Try using `'url' => '/'. $this->params['url']['url']`. – ADmad Sep 26 '14 at 12:28
  • `'url' => '/'` is an argument of create, and `$this->params['url']['url']` this should be placed below? If yes, it redirects me to main page. – Filip Frątczak Sep 26 '14 at 17:55
  • Not below. `$this->params['url']['url']` is concatenated with '/'. I have updated my original answer and the wrapping in comments i causing confusion. Also in future please state your exact CakePHP version. – ADmad Sep 27 '14 at 04:40