View Full Version : Another Forms Submit Question ...
snowball
12-14-2002, 05:21 PM
Hi
This is another question a bit like Gary's below ....... I have a form which I want to be able to submit automatically (on load of the page/form without waiting for the user to press submit) when a particular template being used is no.2 but not if no.1 .......
<script language="JavaScript1.1">
<!--
function saveForm() {
document.htmlForm.target="_self"
document.htmlForm.submit
}
//-->
</script>
<FORM METHOD=POST ACTION="$cgiurl" name="htmlForm">
$Account::hidden_variables
<script language="JavaScript1.1">
<!--
if ("$INPUT{'template'}" === "template_2.dat") {
document.write('<input type=\"hidden\" name=\"_file_name_\" value=\"gallery.html\">');
} else {
document.write('<input type=\"hidden\" name=\"_file_name_\" value=\"index.html\">');
}
//-->
</script>
<input type="hidden" name="dir" value="">
<input type="Submit" name="save" value = " $lang::ut5 " onClick="saveForm(this.form);">
</FORM>
I thought I had to alter the <input type=submit .... line and I tried using onLoad instead of onClick, but it didn't work.
Does anyone have a good ideas?
Would be really greatful.
snow ........
chrismiceli
12-14-2002, 05:56 PM
like this?
<body onLoad="document.htmlForm.submit()">
snowball
12-14-2002, 10:40 PM
Thanks for trying ....... but doesn't work I'm afarid .... It gets stuck on the page and keeps doing that same thing over and over again.
I think that's because the onClick did originally run a script called "saveForm" rather than submitting direct.
Any other ideas ??????
snow .........
snowball
12-16-2002, 10:23 PM
Any other ideas anyone ???? ...........
Really would appreciate help from anyone who thinks they may have an answer.
Thanks
snow
whammy
12-17-2002, 12:51 AM
It may help if you posted a link to the page in question, or the relevant code (although a link would be better!).
It sounds like you're submitting the page to itself over and over without changing anything.
snowball
12-21-2002, 09:24 PM
Thanks for the suggestion ...... Here's all the code for the page:
#!/usr/bin/perl
$|=1;
BEGIN {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1");
}
require "variables.pl";
require "dblib.pl";
require "acc_auth2.pl";
require "header_footer.pl";
print "Content-type: text/html\n\n ";
&Account::initialize;
&Account::verify_user;
if ($INPUT{'tfghemplate'}) { &template; }
elsif ($INPUT{'preview'}) { &save_template; }
elsif ($INPUT{'save'}) { &save_template; }
elsif ($INPUT{'template'}) { &template; }
elsif ($INPUT{'file'}) { &template; }
elsif ($INPUT{'rename'}) { &rename; }
elsif ($INPUT{'rename_final'}) { &rename_final; }
elsif ($INPUT{'new'}) { &new; }
else { &main; }
sub main {
&Account::header($lang::ut1);
print <<EOF;
<TABLE WIDTH=85% CELLSPACING=0 CELLPADDING=5 BORDER=0 style=\"margin-left:35px\"><TR><TD>
<br><br><font face=$font_face size=$font_size>
<b>$lang::ut2</b>
<BR><BR>
EOF
if (-e "$path/templates") {
opendir (DIR, "$path/templates") || &error("can not open $path");
@temps = grep {(/^template\_[0-9]*\.dat/)} readdir(DIR);
close (DIR);
$t_path = "$path/templates";
}
else {
opendir (DIR, "$path") || &error("can not open $path");
@temps = grep {(/^template\_[0-9]*\.dat/)} readdir(DIR);
close (DIR);
$t_path = $path
}
@tempnums = map { (my $num = $_) =~ s/\D//g; $num } @temps;
@tempnums = sort { $a <=> $b }@tempnums;
foreach (@tempnums) {
$ttem = "template_" . $_ . ".dat";
open (HEAD, "$t_path/$ttem");
@ffil = <HEAD>;
close (HEAD);
print <<EOF;
<A HREF="$files::templates?account=$Account::cata_acc&session=$Account::session&dir=$INPUT{'dir'}&template=$ttem"><b>$ffil[0]</b></A>
- $ffil[1]
<BR><BR>
EOF
}
print <<EOF;
<BR><BR></TD></TR>
</TABLE>
EOF
&Account::footer;
exit;
}
########## TEMPLATE ###########
sub template {
$dir = $INPUT{'dir'};
$dir =~ s/^\///;
if ($dir =~ /\.\./) { &error("hacking attempt"); }
if ($dir) { $dir_plus = "$Account::dir_acc/$dir"; }
else { $dir_plus = $Account::dir_acc; }
$template = $INPUT{'template'};
$template =~ s/\.\.//gi;
undef $/;
if (-e "$path/templates/$template") {
open (HEAD, "$path/templates/$template");
$ffil = <HEAD>;
close (HEAD);
}
else {
open (HEAD, "$path/$template");
$ffil = <HEAD>;
close (HEAD);
}
@afil = split(/\n/,$ffil);
$line1 = $afil[0];
$line2 = $afil[1];
if ($INPUT{'file'}) {
open (HEAD, "$dir_plus/$INPUT{'file'}");
$sfile = <HEAD>;
close (HEAD);
$sfile =~ s/<!--START EZ_WEB TEMP-->\n//gm;
$sfile =~ s/<!--END EZ_WEB TEMP-->(.|\n)*//gm;
@asfile = split(/\n/,$sfile);
foreach $line (@asfile) {
@aline = split(/\%\%/,$line);
$ffil =~ s/\%$aline[1]\%/$aline[2]/g;
}
$ffil =~ s/\%.*\%//g;
}
else {
$defalt = $ffil;
$defalt =~ s/START_DEFAULTS\n//gm;
$defalt =~ s/END_DEFAULTS(.|\n)*//gm;
$ffil =~ s/START_DEFAULTS(.|\n)*?END_DEFAULTS\n//m;
@asfile = split(/\n/,$defalt);
foreach $line (@asfile) {
chomp($line);
@aline = split(/\%\%/,$line);
$ffil =~ s/\%$aline[0]\%/$aline[1]/g;
}
$ffil =~ s/\%.*\%//g;
}
$ffil =~ s/.*\n.*\n//m;
&Account::header($lang::ut1);
$dir_list = &Account::dir_select_list($dir);
print <<EOF;
<script language="JavaScript1.1">
<!--
function previewForm() {
document.htmlForm.target="preview"
document.htmlForm.submit
}
function saveForm() {
document.htmlForm.target="_self"
document.htmlForm.submit
}
//-->
</script>
<FORM METHOD=POST ACTION="$cgiurl" name="htmlForm">
$Account::hidden_variables
<script language="JavaScript1.1">
<!--
if ("$INPUT{'template'}" === "template_2.dat") {
document.write('<input type=\"hidden\" name=\"_file_name_\" value=\"gallery.html\">');
} else {
document.write('<input type=\"hidden\" name=\"_file_name_\" value=\"index.html\">');
}
//-->
</script>
<input type="hidden" name="dir" value="">
<input type="hidden" name="directory" value="$INPUT{'account'}">
<input type="hidden" name="website_name" value="$Account::website_name">
<input type="hidden" name="website_des" value="$Account::website_des">
<input type="hidden" name="p1" value="$Account::custom_10">
<input type="hidden" name="p2" value="$INPUT{'pic2'}">
<input type="hidden" name="p3" value="$INPUT{'pic3'}">
<input type="hidden" name="p4" value="$INPUT{'pic4'}">
<input type="hidden" name="p5" value="$INPUT{'pic5'}">
<input type="hidden" name="p6" value="$INPUT{'pic6'}">
<input type="hidden" name="p7" value="$INPUT{'pic7'}">
<input type="hidden" name="p8" value="$INPUT{'pic8'}">
<input type="hidden" name="p9" value="$INPUT{'pic9'}">
<input type="hidden" name="p10" value="$INPUT{'pic10'}">
<input type="hidden" name="psize" value="$Account::custom_9">
$ffil
################# HERE'S THE SUBMIT I WOULD LIKE TO HAPPEN WITHOUT WAITING IF TEMPLATE IS no.2 USING THIS OPERATION:
if ("$INPUT{'template'}" === "template_2.dat") {
}
###############################################################################################
<input type="hidden" name="template" value="$template">
<div align="center"><input type="Submit" name="save" value = " $lang::ut5 " onClick="saveForm(this.form);"></div>
</FORM><br><br>
EOF
&Account::footer;
exit;
}
########## SAVE TEMPLATE ##########
sub save_template {
$template = $INPUT{'template'};
$picture = $INPUT{'p1'};
$picsize = $INPUT{'psize'};
$websitename = $Account::website_name;
$websitename =~ s/\"/\\\"/g;
$websitename =~ s/\'/\\\'/g;
$ntemplate = $template;
$ntemplate =~ s/\.dat$//;
undef $/;
if (-e "$path/templates/$ntemplate.html") {
open (HEAD, "$path/templates/$ntemplate.html");
$file = <HEAD>;
close (HEAD);
}
else {
open (HEAD, "$path/$ntemplate.html");
$file = <HEAD>;
close (HEAD);
}
$hide ="<!--START EZ_WEB TEMP-->\n";
$hide .= "<!--\%\%template\%\%$template\%\%-->\n";
while ( ($key, $value) = each( %INPUT) ) {
unless (($key eq "account") || ($key =~ /_[0-9]*\.dat/) || ($key eq "session") || ($key eq "dir") || ($key eq "_file_name_")) {
if (($key eq "loage") && ($value < "18")) {
$value = "18";
}
$value =~ s/\"/\\\"/g;
$value =~ s/\'/\\\'/g;
$value =~ s/\r/<br>/g;
$value =~ s/\n//g;
$hide .= "<!--\%\%$key\%\%$value\%\%-->\n";
}
$file =~ s/\%$key\%/$value/gi;
}
$hide .= "<!--END EZ_WEB TEMP-->\n";
if ($INPUT{'save'}) {
$html = $file;
# &add_header;
$file_name = $INPUT{'_file_name_'};
@filsplit = split(/\./,$file_name);
$filsplit[0] =~ s/![a-z|A-Z|0-9]//g;
unless (($filsplit[1] eq "html") || ($filsplit[1] eq "htm") || ($filsplit[1] eq "shtml")) {
&Account::header;
print <<EOF;
<BR>
<table width=85% cellpadding=5 border=0 cellspacing=0 bgcolor=$table style=\"margin-left:35px\">
<TR><TD><font face=$font_face size=$font_size color=$text_table>
<B>$filsplit[0].$filsplit[1]</B> $lang::ut7
</TD></TR></TABLE>
EOF
&Account::footer;
exit;
}
$nfilen = "$filsplit[0].$filsplit[1]";
if ($Account::hf_on eq "on") {
undef $/;
if ($Account::file_header) {
open (HEAD, "$path/$Account::file_header");
$hheader = <HEAD>;
close (HEAD);
if ($Account::file_header =~ "headers") {
$hheader =~ s/.*\n//;
}
}
if ($Account::file_footer) {
open (HEAD, "$path/$Account::file_footer");
$ffooter = <HEAD>;
close (HEAD);
if ($Account::file_footer =~ "footers") {
$ffooter =~ s/.*\n//;
}
}
$/="\n";
$content = &headers::add($html,$hheader,$ffooter);
}
else {
$content = $html;
}
open (HEAD, ">$dir_plus/$nfilen") || print("writing $dir_plus/$nfilen $!");
print HEAD "$hide";
print HEAD "$content";
close (HEAD);
&Account::header($lang::ut1);
print <<EOF;
<TABLE WIDTH=85% CELLSPACING=0 CELLPADDING=0 BORDER=0 style=\"margin-left:35px\"><TR><TD>
<script language="JavaScript1.1">
<!--
if ("$INPUT{'template'}" === "template_2.dat") {
document.write('<FONT FACE=$font_face SIZE=$font_size color=$text_table><BR><BR>$lang::m66<BR></TD></TR>');
document.write('<TR height=20><TD bgcolor=$table_head_bg>');
document.write('<meta http-equiv=\"refresh\" content=\"1;URL=$files::templates?account=$Account::cata_acc&session=$Account::session&dir=&template=template_1.dat&pic1=$picture&picsize=$picsize\">');
document.write('<FONT FACE=$font_face SIZE=$font_size COLOR=$text_table_head> <B>$lang::m52</B></FONT></TD></TR>');
document.write('<TR><TD><br><br><div align=\"center\"><img src=\"/images/ws-page.jpg\" width=\"200\" height=\"150\" border=\"1\"></div><br></TD></TR>');
document.write('</TABLE><BR><BR><BR>');
} else {
document.write('<FONT FACE=$font_face SIZE=$font_size color=$text_table><BR><BR>$lang::m67<BR></TD></TR>');
document.write('<TR height=20><TD bgcolor=$table_head_bg>');
document.write('<meta http-equiv=\"refresh\" content=\"1;URL=$files::wwwboard?account=$Account::cata_acc&session=$Account::session&action=newboard&wwwboard_name=$websitename&g_bgcolor=ffffff&g_text=000000&g_link=0057fe&g_vlink=ff4848\">');
document.write('<FONT FACE=$font_face SIZE=$font_size COLOR=$text_table_head> <B>$lang::m51</B></FONT></A></TD></TR>');
document.write('<TR><TD><br><br><div align=\"center\"><img src=\"/images/ws-board.jpg\" width=\"200\" height=\"150\" border=\"1\"></div><br></TD></TR>');
document.write('</TABLE><BR><BR><BR>');
}
//-->
</script>
</TD></TR></TABLE>
EOF
&Account::footer;
exit;
}
else {
#### PRINT PREVIEW ####
print "$file";
}
exit;
}
1;
whammy
12-22-2002, 05:00 AM
The code for submitting a form automatically is no more difficult than:
<script type="text/javascript">
<!--
document.MYFORMNAME.submit();
// -->
</script>
You just need to put that in the appropriate place in your PHP code. :)
brothercake
12-22-2002, 07:26 AM
Or did you want the PHP to handle all that? Submit and collect the information returned, without breaking stride, as it were?
Well if you do ... that's, er, rather complicated. I won't pretend to understand, but instead defer you to someone who might know what to say ...
But I do know of an API that looks good for this kind of thing and seems to come highly recommended - check out Snoopy (http://snoopy.sourceforge.net/)
<edit>
Oh I've noticed you're working with Perl; I had assumed PHP from the $ variables.
In which case I don't know; but the whole "server-side handles all the form re-processing" still feels like it may suit you better - an added level of complication though it is - it may well be easier to maintain in the long run that way.
</edit>
<edit_ps>
whammy - your sig is so true; never again will repetitive key-stroke sequences curse my working day :)
</edit_ps>
snowball
12-22-2002, 05:25 PM
Hi guys .... thanks for looking at this.
Yes this is a cgi script with some java code in it ..... And I can't believe that what I want to achieve is not possible. It seems to me to be such a simple request.
The code as it is above, at the point where I have inserted the ######## HERE THE FORM I WANT TO SUBMIT ...... ETC ETC
produces a page where the only thing on it is a submit button with a whole load of hidden values in the form. The operation works great, but you sit on this page until you press "Submit". I just want (effectively) to have the button press itself without the user having to do anything.
using ...... document.htmlForm,submit() causes the form to submit over and over again. You'll see in the original that the submit button has an ..... onClick="saveForm(this.form);" ..... command in it, which calls on the saveForm function higher up the page.
I've tried moving those commands down, but if I do nothing happens at all. The page just sits there with an error saying "object does not support this property or method".
So I'm stuck on either a page that just sits there (doing nothing with an error) or a form that resubmits endlessly, rather than the submit once and move on to the next page, which is what the page with the submit button achieves now.
If anyone has any other ideas I would be really, really greatful.
Thanks
snow
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.