Gossamer Forum
Home : General : Perl Programming :

Perl problem - how to make a form auto submit

Quote Reply
Perl problem - how to make a form auto submit
Hi there, I have a strange problem, I have a web page with hidden inputs on a form, the page is always showna nd theres really no need for it. Is there a way I can incorporate a piece of java script into the form to by pass this page. After a quick search I found this

javascript:document.FormName.submit();

but I am unsure where this should be added, looks like between form tags and unsure on the correct syntax for it.

Any help would be appreciated. the form is in the add.cgi

(I apologise I know this has nothing to do with links or any of the gossamer products and if this should not be posted here, can a moderator please let me know)

Quote Reply
Re: Perl problem - how to make a form auto submit In reply to
Does the form have to be submitted at the same time as add.cgi?

I'm not sure you can submit two at once.



Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Perl problem - how to make a form auto submit In reply to
Sorry that was a bit vague in explanition on my behalf.
I won't show all the coding but here is a snippet

<FORM method=POST action="add.cgi">
<input type=hidden name="postmode" value="UPDATE">
<input type=hidden name="OrderID" value="2001071300381205438">
<input type=hidden name="previouspage" value="http://www.myurl.com/received.html">

blaa blaaa </form>

The form is submitting hidden information, unfortunately I cannot remove this page as its needed by another script later on in the payment process. Therefore instead of the visitor seeing this page I just want to simply bypass it.
I have tried a meta refresh but that won't work, I contacted the script owner and he told me to use the javascript auto submit, which I have never used or heard of.

I just need to know where to insert the code and roughly the correct syntax for it.

(Also Paul whilst your here, there is no problem posting these types of questions on this forum is there)

Quote Reply
Re: Perl problem - how to make a form auto submit In reply to
Ahh, sorry I was getting confused thinking add.cgi was the Links2 add.cgi.

Ok, in the <FORM> tag add name="MyForm"

Then try adding that code into the <BODY> tag...

<BODY onLoad="javascript:document.MyForm.submit();">

Yes your question is fine. This forum isn't just for GT products.

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Perl problem - how to make a form auto submit In reply to
print "<FORM method=POST action=\"$programfile\" name=\"MyForm\"> \n";
print "<input type=hidden name=\"postmode\" value=\"PREVIEW\"> \n";
print "<input type=hidden name=\"submit_preview_info\" value=\"NEWSUBMIT\"> \n";
print "<input type=hidden name=\"OrderID\" value=\"$frm{'OrderID'}\"> \n";
print "<input type=hidden name=\"InfoID\" value=\"$InfoID\"> \n";
print "<input type=hidden name=\"previouspage\" value=\"$frm{'previouspage'}\"> \n\n";
foreach $line (@orders) {print "<input type=hidden name=\"order\" value=\"$line\"> \n"}
print " \n\n";


Also then added this into my html file:-

<BODY TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" BGCOLOR=FFFFFF onLoad="javascript:document.MyForm.submit();">

But it produces an HTTP 500 - Internal server error

Any other ideas

Quote Reply
Re: Perl problem - how to make a form auto submit In reply to
Shouldn't:

foreach $line (@orders) {print "<input type=hidden name=\"order\" value=\"$line\"> \n"}

be:

foreach $line (@orders) {
print "<input type=hidden name=\"order\" value=\"$line\">\n";
}

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: Perl problem - how to make a form auto submit In reply to
First of all, a big thank you to Paul for the code, and also a big thank you to Glennu for pointing out that error.

The program works like a dream.



Quote Reply
Re: Perl problem - how to make a form auto submit In reply to
No problem.

If you dont want to keep using print "bla..."; and escaping all the quotations you can use:

print qq| all html here |;

Do you know you've used \n within html code?...shouldn't it be <BR> ?




Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com