[SOLVED] Code to make dummy form and submit itself (hidden/auto) [RENAMED]
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?)
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:
On page load, I get the value of 2 dummy inputs and place in vars "RedirURL" and "PortalAction"
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()
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…
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).
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 ?