Can´t submit form content of a jQuery UI modal windows

Can´t submit form content of a jQuery UI modal windows

I like to use the jQuery UI modal dialog, to create new users in a database by using php code. I get the modal code example from the jQuery UI page and the form is opend in the modal window. The orignal code example just adds the form datas into a table on the page with /$( "#users tbody" ).append... and so on.

But I need to submit the form datas to a php file. So far so good. I thought, okay I´ve just to replace the append code part with
  $("form#modal-form").submit();
and it´s should be working. But it doesn´t, and I don´t get it why.


I do the modal windows with:

  1. dialog = $( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
    
          "Create User": addUser,
    
          Cancel: function() {
            dialog.dialog( "close" );
          }
        },
        close: function() {
          form[ 0 ].reset();
          allFields.removeClass( "ui-state-error" );
        }
          });
And the addUser function:
  1. function addUser() {
        var valid = true;
        allFields.removeClass( "ui-state-error" );
    
        ...validation of the form datas...
    
        if ( valid ) {
            //$( "#users tbody" ).append( "<tr>" +
            //  "<td>" + name.val() + "</td>" +
            //  "<td>" + email.val() + "</td>" +
            //  "<td>" + password.val() + "</td>" +
            //"</tr>" );
            $("form#modal-form").submit();
            dialog.dialog( "close" );
         }
         return valid;
       }

My form looks like this:

  1. <form action="adduser.php" name="modal-form" id="modal-form" method="POST">
    <fieldset>
      <label for="name">Name</label>
      <input type="text" name="name" id="name" value="Jane Smith" class="text ui-widget-content ui-corner-all">
      <label for="email">Email</label>
      <input type="text" name="email" id="email" value="jane@smith.com" class="text ui-widget-content ui-corner-all">
      <label for="password">Password</label>
      <input type="password" name="password" id="password" value="xxxxxxx" class="text ui-widget-content ui-corner-all">
    </fieldset>


All I get is the error

 Too much recursion
Where is my mistake? Can anyone maybe help me?