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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing information from 1 form to another

Status
Not open for further replies.

amanxman

Technical User
Oct 8, 2005
19
NZ
Hi,

I have two forms, the second of which is in the html of the .cgi which results from the first form.

Ie they fill in the first form, which is on a .html file. Clicking submit sends me an email and takes them to thankyou.cgi.

This thankyou.cgi file has a second form on, through which the user can submit another query, without having to input their contact details again (as they've already done it on the first form).

So... Im trying to get the second form-to-email to automatically include information from the first form.

On the first form, the fields I want the 2nd to pick up are:
<input type="text" name="name" maxlength="70" size="30" style="color:#000099" />
<input type="text" name="phone" maxlength="12" size="30" style="color:#000099" />

So on my second form, the fields for obtaining the info from the first are:
<input type="hidden" name="name" value="<%=request.form("name")%>">
<input type="hidden" name="phone" value="<%=request.form("phone")%>">

And submitting the 2nd form sends me an email, and again returns them to the thankyou.cgi page (where they can submit another, if they so wish!!)

However the email I receive from the 2nd form sends the value "<%=request.form(" to me, rather than bringing the info from the first form.

I got the value="<%=request.form("name")%>"> code from another forum, for asp.

Does this passing of info work in .cgi -- if so, what am i doing wrong?!!

Thanks very much in advance
amx
 
In your thankyou.cgi at the stage where you print the form, you can do it like this
Code:
...........
$preview_form_name = $cgi->param('name');
print qq~<input type="hidden" name="name" value="$preview_form_name">~;

$preview_form_phone = $cgi->param('phone');
print qq~<input type="hidden" name="phone" value="$preview_form_phone">~;
...........
i wonder how did you manage to parse the parameters from your first form....


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Hi,

Thanks for the quick reply.

so...

The second form on thankyou.cgi currently reads;

<form method="post" action="/cgi-bin/thankyou.cgi">
<input type="hidden" name="Additional Order" value="Additional Order Enquiry from Website" />
<input type="hidden" name="name" value="<%=request.form("name")%>">
<input type="hidden" name="phone" value="<%=request.form("phone")%>">
<center>
<table width="350px" border="0" align="center" cellpadding="5" cellspacing="2">
<tr>
<td height="46" align="right"><p>Characters
</p>
</td>
<td align="left"><input type="text" name="Characters" maxlength="70" size="30" style="color:#000099" />
</td>
</tr>
<tr>
<td height="114" align="right"><p>Your<br />
<strong>Comments</strong> &amp; <strong>Questions</strong>
</p>
</td>
<td align="left"><textarea name="textarea" wrap="virtual" rows="5" cols="24" style="color:#000099"></textarea></td>
</tr>

<tr>
<td align="center" colspan="2"><input type="image" src="assets/images/send.gif" name="submit2" />
</td>
</tr>
</table>
</form>

Would I just need to directly replace the lines:
<input type="hidden" name="name" value="<%=request.form("name")%>">
<input type="hidden" name="phone" value="<%=request.form("phone")%>">

with exactly:
$preview_form_name = $cgi->param('name');
print qq~<input type="hidden" name="name" value="$preview_form_name">~;

$preview_form_phone = $cgi->param('phone');
print qq~<input type="hidden" name="phone" value="$preview_form_phone">~;

Again, thank you heaps for your help
amx
 
depends how you print the form.
you can specify the variables earlier and then change the [red]value="<%=request.form("phone")%>"[/red] to [red]value="$preview_form_phone"[/red]
or you can print them separatly from the others.
It would be a lot easier if you show me the thankyou.cgi source and I'll tell you where you will place these lines.


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Hi,

thanks very much for the reply :)

Below are the codes for the two forms, and the thankyou.cgi script...

First Form
Code:
<form method="post" action="/cgi-bin/thankyou.cgi">
        <input type="hidden" name="Subject2" value="Order Enquiry from Website" />
        <center>
        <table width="350px" border="0" align="center" cellpadding="5" cellspacing="2">  
       <tr>
            <td height="46" align="right"><p>Your <strong>Name</strong></p></td>
            <td align="left"><input type="text" name="name" maxlength="70" size="30" style="color:#000099" /></td>
          </tr>
          <tr>
            <td height="46" align="right"><p>Phone <strong>Number</strong></p></td>
            <td align="left"><input type="text" name="phone" maxlength="12" size="30" style="color:#000099" /></td>
          </tr>
          <tr>
            <td height="114" align="right"><p>Any<br />
                    <strong>Comments</strong> &amp; <strong>Questions</strong></p></td>
            <td align="left"><textarea name="comments" wrap="virtual" rows="5" cols="24" style="color:#000099"></textarea></td>
          </tr>
          <tr>
            <td colspan="2"></td>
          </tr>
          <tr>
            <td align="center" colspan="2"><input type="image" src="assets/images/send.gif" name="submit" /></td>
          </tr>
	 </table>
	    <center>
      </form>


Second form (within the HTML of the .cgi file)

Code:
<form method="post" action="/cgi-bin/thankyou.cgi">
        <input type="hidden" name="Additional Order" value="Additional Order Enquiry from Website" />
        <input type="hidden" name="name" value="<%=request.form("name")%>">
	<input type="hidden" name="phone" value="<%=request.form("phone")%>">
				  <center>
        <table width="350px" border="0" align="center" cellpadding="5" cellspacing="2">
          <tr>
            <td height="114" align="right"><p>Your<br />
                    <strong>Comments</strong> &amp; <strong>Questions</strong></p></td>
            <td align="left"><textarea name="textarea" wrap="virtual" rows="5" cols="24" style="color:#000099"></textarea></td>
          </tr>
 <tr>
            <td align="center" colspan="2"><input type="image" src="assets/images/send.gif" name="submit2" /></td>
          </tr>
        </table>
	    <center>
      </form>

As you can see, the 3rd and 4th lines of the second form have the value="<%=request.form("name")%>" that i'm trying to use at the moment, unsuccessfuly.


Also, if you need it, the script in the .cgi file is as follows;
Code:
use strict;

&process(&init());

sub init { print "Content-type: text/html\n\n"; &getData() }

sub getData 
{
	my $form;
	use CGI qw(:standard);
	my $Form = new CGI;
	for($Form->param)
	{
		( $Form->param($_) =~ /\S/ )			and 
		( $form->{$_} = $Form->param($_) )	and 
		  push @{$form->{Seq}},$_
	}
	$form
}

sub process { &mailMe(shift) and &finis }

sub mailMe 
{
	my($form,$data) = shift;
	my($sendmail,$name,$domain,$email) = 
		('/usr/sbin/sendmail','My website','[URL unfurl="true"]www.mywebsite.co.uk','myemail@email.com');[/URL]
	
$domain =~ s/[\r\n]/ /g;
$email =~ s/[\r\n]/ /g;

        open MAIL, "|$sendmail $email" or die "Can't open sendmail: message = '$!'";
	print MAIL "To: $email\n";
	print MAIL "From: $domain\n";
	print MAIL "Subject: $form->{subject}\n\n";
	print MAIL "Dear $name,\n\n";
	for(@{$form->{Seq}}) { print MAIL "$_\t\t : ",$form->{$_},"\n" and $data = 1 }
	print MAIL "The input form was empty\n" unless $data;
	print MAIL "\n\nYours truly,\nThe Mail Room";
	close MAIL or die "Can't close sendmail: message = '$!'"
}

sub finis 
{
	print STDOUT <<OPE

If you could show me where to put what i'd be forever grateful!

thanks
amx
 
Maybe it makes sense in bigger scripts, but I think all that calling of functions within functions in your CGI just obfuscates what's going on. Straigtening it out makes it a little easier to see what's going on...
Code:
use strict;
use CGI qw(:standard);

print "Content-type: text/html\n\n";

my $form;
my $Form = new CGI;
for($Form->param)
    {
        ( $Form->param($_) =~ /\S/ )            and
        ( $form->{$_} = $Form->param($_) )    and
          push @{$form->{Seq}},$_
    }

my($sendmail,$name,$domain,$email) =
        ('/usr/sbin/sendmail','My website','[URL unfurl="true"]www.mywebsite.co.uk','myemail@email.com');[/URL]
    
my $data;

$domain =~ s/[\r\n]/ /g;
$email =~ s/[\r\n]/ /g;

open MAIL, "|$sendmail $email" or die "Can't open sendmail: message = '$!'";
    print MAIL "To: $email\n";
    print MAIL "From: $domain\n";
    print MAIL "Subject: $form->{subject}\n\n";
    print MAIL "Dear $name,\n\n";
    for(@{$form->{Seq}}) { print MAIL "$_\t\t : ",$form->{$_},"\n" and $data = 1 }
    print MAIL "The input form was empty\n" unless $data;
    print MAIL "\n\nYours truly,\nThe Mail Room";
    close MAIL or die "Can't close sendmail: message = '$!'"

    print STDOUT <<OPE
<form method="post" action="/cgi-bin/thankyou.cgi">
        <input type="hidden" name="Additional Order" value="Additional Order Enquiry from Website" />
        <input type="hidden" name="name" value="[b]$form->{name}[/b]">
yadda yadda yadda
<<OPE
I've not tested the above, but I think it should work.

Incidentally, having two variables called $Form and $form is potentially gonna give you a whole world of problems when you use the wrong one by mistake one day - it's really difficult to spot when debugging.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Although i think that this way of writing is not the best and the most readable, but I guess you'll get better on time.
Actualy I find it very slupy and messy.

The red parts is what I've changed
Code:
use strict;

&process(&init());

sub init { print "Content-type: text/html\n\n"; &getData() }

sub getData
{
    my $form;
    use CGI qw(:standard);
    my $Form = new CGI;
    for($Form->param)
    {
        ( $Form->param($_) =~ /\S/ )            and
        ( $form->{$_} = $Form->param($_) )    and
          push @{$form->{Seq}},$_
    }
    $form
}

[red]sub process { &mailMe(shift)}[/red]

sub mailMe
{
    my($form,$data) = shift;
    my($sendmail,$name,$domain,$email) =
        ('/usr/sbin/sendmail','My website','[URL unfurl="true"]www.mywebsite.co.uk','myemail@email.com');[/URL]
    
$domain =~ s/[\r\n]/ /g;
$email =~ s/[\r\n]/ /g;

    open MAIL, "|$sendmail $email" or die "Can't open sendmail: message = '$!'";
    print MAIL "To: $email\n";
    print MAIL "From: $domain\n";
    print MAIL "Subject: $form->{subject}\n\n";
    print MAIL "Dear $name,\n\n";
    for(@{$form->{Seq}}) { print MAIL "$_\t\t : ",$form->{$_},"\n" and $data = 1 }
    print MAIL "The input form was empty\n" unless $data;
    print MAIL "\n\nYours truly,\nThe Mail Room";
    close MAIL or die "Can't close sendmail: message = '$!'";
    
    [red]&finis($form->{name},$form->{phone});[/red]
}

sub finis
{
	[red]my ($name,$phone)=@_;
	print qq~[/red]
		<form method="post" action="/cgi-bin/thankyou.cgi">
		<input type="hidden" name="Additional Order" value="Additional Order Enquiry from Website" />
		[red]<input type="hidden" name="name" value="$name">[/red]
		[red]<input type="hidden" name="phone" value="$phone">[/red]
		<center>
		<table width="350px" border="0" align="center" cellpadding="5" cellspacing="2">
		<tr>
		<td height="114" align="right"><p>Your<br />
		<strong>Comments</strong> &amp; <strong>Questions</strong></p></td>
		<td align="left"><textarea name="textarea" wrap="virtual" rows="5" cols="24" style="color:#000099"></textarea></td>
		</tr>
		<tr>
		<td align="center" colspan="2"><input type="image" src="assets/images/send.gif" name="submit2" /></td>
		</tr>
		</table>
		<center>
		</form>
	[red]~;[/red]
}


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Absolutly splendid, works a treat (after some tweaking to fit with the rest of me code!)

I used perluserpengo's, but thanks both of you...

The original script is a template from formmail script - i didnt write it myself, wouldnt know where to start!

so learning very slowly....

thanks again
a,x
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top