Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Pass field values from one page to another.

Quote Reply
Pass field values from one page to another.
I have a website with a single template page (eg. template.html) and on this page I have a two page form. So basically the "do" action on the first page is "add_form" then on the second page it is "add_record". I separate the two pages (even though it is the same HTML template) with an IF statement so that if the second page sees the value from the first page it will display the second half of the block. This works well for multiple page forms and it allows you to do conditional forms depending on previous input entries (without a bunch of DHTML and javascript).
Code:

<%if page1field1%>
Second set of form fields.
<%else%>
First set of form fields.
<%endif%>

Here is my question: Is there a global variable that I can create that will automatically create the "hidden" form elements from the first part of the page? Right now I am manually doing "hard coded" hidden forms like this on the second page:

Code:
<input type="hidden" name="page1field1" value="<%page1field1%>">


On each page I do a HIDDEN tag with the previous form's fields on it. Can somebody help me generate a Global Template that will automatically create the previous pages FORM fields (as hidden fields) rather than me hard coding each page?

P.S. I can already see that there are some fields, like "do", that we don't want brought over to the second page, because they will change.
Quote Reply
Re: [LanceWilson2] Pass field values from one page to another. In reply to
You can use the global below:

sub {
my $tags = GT::Template->tags;
my $cgi = $tags->{home}->{cgi};
my $html = '';
foreach (keys %$cgi) {
next if $_ =~ /^do|sid|db/ or !$cgi->{$_};
$html .= qq!<input type="hidden" name="$_" value="$cgi->{$_}">!;
}
return $html;
}

Hope that helps.

TheStone.

B.
Quote Reply
Re: [TheStone] Pass field values from one page to another. In reply to
Yep... that did it. Thank you!
Quote Reply
Re: [LanceWilson2] Pass field values from one page to another. In reply to
I have questions?
If I name this global "hidden_form_value" and then use
<input type="hidden" name="fieldname1" value="<%fieldname1%">
<input type="hidden" name="fieldname2" value="<%fieldname2%">

is this supposed to work and send the appropriate values for fieldname1 and fieldname2 to any template?

Thanks
Quote Reply
Re: [socrates] Pass field values from one page to another. In reply to
I use it to pass values from the same template file but with different sections. So for instance the template asks for a user ID then that is submitted.... then it load the users information and displays the same template and asks for a project that they are looking for... then it loads that information.... etc. it is all a part of the same "template".