0

I'm .load() 'ing some code from a different file, inside this file is a form:

echo $this->Form->create('myForm', array('url' => array('controller' => 'myController', 'action' => 'myAction'), 'id' => 'myForm'));
//my input fields
echo $this->Form->end;

I wanted to be able to submit this form so I used:

$('#table').on('click', '#mySubmitButton', function() {
   $('#myForm').submit();
});

When I now click #mySubmitButton the form is rediecting to myAction but $this->request->data is empty. When I manually point my browser to the file that I'm loading the form works fine, it just wont post the data it gets .load() 'ed

Is this a common problem? And what can I do to get the form to submit properly?

Thanks

.load() code:

$(document).ready(function () { 
    $('#table1').load('link_to_file');
});

HTML output of the form:

<form id="myForm" accept-charset="utf-8" method="post" action="link_to_file"></form>
sharif9876
  • 680
  • 6
  • 19
  • If you write in console `$('#myForm').submit();` do you have the data sent (network tab)? – keiv.fly Jun 01 '14 at 18:05
  • Do you see the form in DOM in browser debug? – keiv.fly Jun 01 '14 at 18:06
  • Show the javascript code with load(). Show the html output of a file where you create a form. – keiv.fly Jun 01 '14 at 18:07
  • I've added the code for .load() and the HTML form output. – sharif9876 Jun 01 '14 at 18:17
  • And the data is not sent when i write $('#myForm').submit(); in the console – sharif9876 Jun 01 '14 at 18:18
  • So how you suppose to post data if the form is empty? Where are the fields that should pass form data? – keiv.fly Jun 01 '14 at 18:21
  • They are being outputted, but below that line, after the form tag has been closed off, there are quite a few of them thats why I haven't written them in here. When I submit this form by going to the file manually instead of using .load() it all works fine, so I don't think it has anything to do with the HTML that's being generated – sharif9876 Jun 01 '14 at 18:25
  • Can you show the code with id=table1? – keiv.fly Jun 01 '14 at 18:26
  • Probably your form is inside a table tag. Then it cannot work. See http://stackoverflow.com/questions/5967564/form-inside-a-table – keiv.fly Jun 01 '14 at 18:32

1 Answers1

1

A form is not allowed to be a child element of a table, tbody or tr.

The other way around is acceptable (table is a child element of a form).

See the following question Form inside a table

Community
  • 1
  • 1
keiv.fly
  • 3,343
  • 4
  • 26
  • 45