Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forms and cgi

Status
Not open for further replies.

georgeous

Programmer
Jul 11, 2001
38
0
0
GB
I have a form which passes variables to a cgi script which then prints out the values on the next page.
How can i get the cgi script to print to a set format.
at the moment, it just lists the form parameters in a big list, but i want them to be spaced nicely on the page.
this is my code so far...


print &quot;<html><head><title>Form output</title></head><body bgcolor=#000099>&quot;;

print &quot;<h2>results from the form post</h2>\n&quot;;
foreach $key (keys(%FORM)) {

print &quot;$FORM{$key}<br>&quot;;
}

print &quot;</body></html>&quot;;


I think the main problem is me using the 'foreach' command, but i don't know how else to do it.

any ideas??
 
You just need to insert html tags into your output to create valid html. For instance, you might put all of your outputs in a table.

Code:
print '<table width=600>';
foreach $key (keys(%FORM)) { 
    print &quot;<tr><td>$key</td><td>$FORM{$key}</td></tr>\n&quot;;
}
print '</table>';
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
thats great, but that will still print them in one long line
What if i want to space them out, like if i want to put empty or coloured tags in between each key,
is there any way I can do this?
 
That snippet should not produce one long line (as viewed in a browser). It should produce a series of table rows, each containing a key and its associated value.

The general idea is that your cgi must produce compliant HTML. So, dream up the html that would paint the page the way you want it and then write your perl to build that output. If you want empty table cells in the table row, then simply put them there.

Code:
print '<table width=600>';
foreach $key (keys(%FORM)) { 
  print &quot;<tr><td width=25%>$key</td>
    <td width=25%><br></td>
    <td width=25%>$FORM{$key}</td>
    <td width=25%><br></td>
    </tr>\n&quot;;
}
print '</table>';
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top