Navigation

    Netgate Discussion Forum
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search

    [SOLVED] Code to make dummy form and submit itself (hidden/auto) [RENAMED]

    Captive Portal
    2
    2
    1662
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dylanh724 last edited by

      EDIT: Solved it myself.. instead of submitting the form, I used jQuery button submit:

      $( '#accept' ).click()
      

      (PS – this code below may be pretty useful to some of you............. edited to working code)

      (original topic: Dummy form submits itself, doesn't work, but manual click works?)

      Hi,

      For some reason I'm having trouble with a custom POST – if I make a form with javascript and submit it, then it just refreshes the page. However, if I make a form and manually press the button, it redirects fine!

      What is the php post code for a successful login without authentication? Maybe this will help me.. let's say redirect url is cnn.com

      http://pfsip:8000/index.php?redirurl=cnn.com&accept=(the name of the button?? or is this the portal action?)

      If anyone can clarify, that'd be great -- thanks!

      If curious, here is what I'm doing:

      1. On page load, I get the value of 2 dummy inputs and place in vars "RedirURL" and "PortalAction"

      2. This code generates a dummy form and submits itself... but for some reason when I programatically (is that a word? lol) submit, it just refreshes and doesn't log client in ... but if i just generate the button, click it manually, works fine. Strange! Using this:

      
      // Create dummy form and submit
              var submit_form = document.createElement('form');
              submit_form.method = 'POST';
              submit_form.action = PortalAction; // Obtained from $PORTAL_ACTION$ temp element
              submit_form.display =  'hidden';
      
              // redirurl
              var input_redirurl = document.createElement('input');
              input_redirurl.name = 'redirurl';
              input_redirurl.type = 'HIDDEN';
              input_redirurl.value = RedirURL; // Obtained from $PORTAL_REDIRURL$ temp element
              submit_form.appendChild(input_redirurl);
      
              // submit btn
              var btnSubmit = document.createElement('input');
              btnSubmit.name = 'accept';
              btnSubmit.type = 'SUBMIT';
              btnSubmit.value = 'accept';
              submit_form.appendChild(btnSubmit);
      
              // Add to form and submit
              document.body.appendChild(submit_form);
              $( '#accept' ).click()
      
      

      (I'm using PFS for 2 devices at the same time, if you are wondering why I must do it this way – When the user logs in main form, it goes thru a bunch of javascript functions before finally making a PFS form and submitting itself. 99% works... just this submit button not working correctly unless manually clicked)

      1 Reply Last reply Reply Quote 0
      • M
        mikegyver last edited by

        Hi Dylan,

        THANK YOU !!!

        After days searching on Google, I still couln't figure out what was happening with my "programatically ;)" submit button, then I found this topic !
        I have the EXACT SAME issue, what a relief to find someone who could finally solve this.

        I'm a beginner in html/js and stuff (started only 2 weeks ago) so I just copy/pasted your code which did…
        ...
        Nothing :(

        Then I noticed the last line looked like jQuery stuff (you confirmed this at the beginning of this topic), so I thought it would be a good idea to add this to my code :

        but it didn't help.

        Of course I changed PortalAction and RedirURL to my own variables.
        I also put alert('xxx') right before and right after your code : I can see both but nothing happens.

        Since I know nothing in jQuery, I don't know if I should add a ; right after the last line of code :

        $( '#accept' ).click()
        

        I tried though, but it didn't change anything neither.

        Thanks to you I'm really close to the behavior I want to get from my portal page, but maybe I need help from a more experienced person.
        Could you suggest something obvious I may have missed ?

        I can post my code if needed, but it's part of a biggest website so it would look a bit weird out of its context).

        Edit :
        I changed PortalAction and RedirURL to static urls, didn't help.
        I also commented this line :

        //submit_form.display =  'hidden';
        

        Shouldn't I be able to see the form appear on the page then ? I mean, btnSubmit should be visible, right ?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post