Page 4 of 4 FirstFirst ... 234
Results 31 to 39 of 39

Thread: Dynamic Form submit

  1. #31
    Ext JS Premium Member
    Join Date
    Apr 2007
    Posts
    188

    Default

    oops, my bad, change "url" to "action" in the form init!

  2. #32

    Default

    Quote Originally Posted by Darklight View Post
    oops, my bad, change "url" to "action" in the form init!
    I saw that and already made that change with the same results.

    I was reading back in the posts to your solution on page 1. Do I still need to have a form tag in the HTML as well as the Ext generated one?

    Edit: NVM, I tried adding the form tag in the html code and the ext form disappeared.

  3. #33

    Default Ok, got it working

    Here's my code. It looks a lot like one of the previous posts. I could have sworn I tried this earlier.

    JS
    Code:
        var regForm = new Ext.form.Form({
            labelWidth: 100,
        });
    
        regForm.addButton('Submit Registration', function(){
            if (regForm.isValid()) {
                var frmRegister = document.getElementById(regForm.id);
                frmRegister.method = 'POST';
                frmRegister.action = 'event_confirm.asp';
                frmRegister.submit();
            }
        });

  4. #34
    Ext JS Premium Member
    Join Date
    Apr 2007
    Posts
    188

    Default

    here is the code to a form of mine that works (no form tag in html, just a <div> that the form renders into)
    Code:
    Ext.onReady( function () {
      FormLogin = new Ext.form.Form( { id: 'FormLogin', action: 'index.cfm' });
      FormLogin.addButton( 'Login', function () {
        Ext.get( 'FormLogin' ).dom.submit();
      });
      FormLogin.render( "DivLoginForm" );
    });

  5. #35
    Sencha User murphy's Avatar
    Join Date
    Apr 2007
    Posts
    10

    Default

    Quote Originally Posted by tpattison View Post
    Here's my code. It looks a lot like one of the previous posts. I could have sworn I tried this earlier.

    JS
    Code:
        var regForm = new Ext.form.Form({
            labelWidth: 100,
        });
    
        regForm.addButton('Submit Registration', function(){
            if (regForm.isValid()) {
                var frmRegister = document.getElementById(regForm.id);
                frmRegister.method = 'POST';
                frmRegister.action = 'event_confirm.asp';
                frmRegister.submit();
            }
        });
    This look like mine here http://extjs.com/forum/showpost.php?...2&postcount=23

  6. #36

    Default

    Quote Originally Posted by murphy View Post
    Yep, I just couldn't remember who posted it at the time. Thanks Murphy & Darklight!

  7. #37
    Ext JS Premium Member
    Join Date
    Mar 2007
    Posts
    173

    Default Getting the form element

    Here's another way to get the DOM form element. You don't need to add an "id" to the form, although you do need to know the "id" of the element you are rendering the form into. Useful if you are using "old school" submit. You can also add hidden form fields etc to the form.


    Code:
    var container = document.getElementById("DivLoginForm");
    var formElement = container.getElementsByTagName("form")[0];
    formElement.action = "go-do-it.php";
    
    ...
    
    formElement.submit();
    Max

  8. #38
    Sencha User
    Join Date
    Mar 2007
    Posts
    210

    Default

    or much easier and no setting id:
    Code:
    Ext.onReady( function () {
      function oldSubmit(){
        Ext.get( FormLogin.id ).dom.submit();
      };
      FormLogin = new Ext.form.Form( { url: 'index.php', method: 'POST' });
      FormLogin.addButton( 'Login', oldSubmit );
      FormLogin.render( "DivLoginForm" );
    });

  9. #39
    Sencha User
    Join Date
    Mar 2007
    Posts
    210

    Default

    I got to a situation where I needed to set params for a POST on the form.submit which you can't do when doing a standard dom submit. The value was also depending on what rendered button I pressed and the buttons were not form buttons.

    I did it like this, but I'm sure if you wanted to add it hidden before you rendered the form and then set the TextField value in the submit function you could do it that way too. I think my way is easier
    Code:
      function oldSubmit(){
        FormLogin.add( hidden = new Ext.form.Field({name: 'chtype', value: 'valueHoweverYouGetIt', inputType : 'hidden'}));
        hidden.render(FormLogin.id);
        Ext.get( FormLogin.id ).dom.submit();
      };

Page 4 of 4 FirstFirst ... 234

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •