Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Using multiple forms to submit

Quote Reply
Using multiple forms to submit
I was just wondering if anyone new of a way to use multiple forms to add a link rather than using one page to list all form elements? If you have a large amount of form data to be entered, it would be nice to break this up into two or more different pages and then submit it using add.cgi. I know its possible to use another cgi program to do this and then have the final page use the <form action="<%db_cgi_url%>/add.cgi" enctype="multipart/form-data" method="POST"> to submit, but it would be nice to use GT tags as conditionals rather than trying to play with JavaScript to do what you want as an example.

Anyone?
Perl Hopefull
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
This is definatly possible. What I would do, is have something like;

Code:
<%if step == 1%>
<%include add_step_1.html%>
<%elsif step == 2%>
<%include add_step_2.html%>
<%elsif step == 3%>
<%include add_step_3.html%>
<%else%>

... then in each of those include templates, have the appropriate parts of the form. Now, for example, after step 1, you need to hold the information they sent through previously. Just use <input type=hidden ...> HTML tags to hold these details. Repeat this until the last step, and then all the details should be there.

Hope that makes sense Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Using multiple forms to submit In reply to
Hey Andy..thanks for the post Smile

I haven't gotten a chance to go home and play with this yet, but I was wondering how were going to check the first step? How would you perform the check <%if step == 1%>...use referrers? Or were you talking about including a form field value that it would use to validate maybe? Also, once the first page is submitted, how will it return step_2 unless you use a separate cgi script? Another way of looking at this would be to use some sort of global that would increment the number of pages using a script....but somehow I don't think your post was meant to be this involved......must be midterm exams getting to me!

Thanks for any additional light you can shed for me....I'm gonna go play with this later tonight.
Perl Hopefull

Last edited by:

stilton: Oct 15, 2003, 7:52 PM
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
... and if this would work with add.cgi what about required fields? That would lead to an error as I think.

Example: You have a required field in step3 but you start at/submit step1 => missing required field.

Using a input-type-hidden option for this would make the required (field) obsolet.

Regards,
Manu

Shopping Portal Shop-Netz.de® | Partnerprogramme | Flugreisen & Billigflüge | KESTERMEDIA e.K. | European Affiliate Marketing Forum.
Quote Reply
Re: [ManuGermany] Using multiple forms to submit In reply to
I've been playing with this but obviously I'm not on the right track....in fact I fell off the track awhile ago and now I'm sitting there trying to .....enough metaphors....

Anyone actually tried doing this successfully? If so, I'd appreciate a walk thru!

tia
Perl Hopefull
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
At the top of your page you could have <%ifnot step%><%set step=1%><%endif%>

Then you can include an extra hidden input <input type=hidden name=step value=2> on the first page.

I'm not sure whether this will work if you POST the form but if you use GET, the next page will be able to read the step=2 value from the url.
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
Hi,

I solved multiple page problems for my postcards plugin, fairly simply, but it requires a change to add.cgi. The suggestion posted here won't work, because add.cgi doesn't know to just pass the data back out to a "confirm" page. You need to modify add.cgi to check the "submit" parameter and do something different if the form is not on the last page. ( "confirm" pages can be set up the same way, just pass in an add_confirm page and allow a user to confirm/preview the results. This can go on as long as a user presses "preview". Once they press "confirm" they get the "add_success/fail" page.)

There is an option to use one page, or follow a form through step by step.

What you need to do, basicly, is to have a script just pass all the data it got in, back to the next template page, until it gets a "done" or similar command.

Make sure you write out all the tags, and while it's extra coding, it's _best_ to hard-code the tags you expect to get back into each template (that prevents users from trying to do nasty things).

On the first page, you get something like "add1.html" as the template, and when the user submits this, a "doNextPage=add2.html" tag is passed back.

The add.cgi script just looks for "doNextPage" and if it's not empty, it passes the data in %IN to the SiteHTML::display routine with the template set as what is in "doNextPage". If it's equal to "submit" then go on to the "add" routines. (actually you test for this before you jump to the next template).

Links will give you errors if the template doesn't exist, etc. so you don't need to worry about it -- unless you want to do something like track hack attempts.

add2.html _should_ have hidden tags for all the data it just passes through, "text" or whatever fields for data you want the user to still be able to change or add. You should *not* use a routine that takes what's in %IN and generates a hash -- this is a security hole.

Each successive template will have more and more hidden tags (and/or visible ones).

You can do this as many times as you like, the script _doesn't_ care as long as it gets a valid template name to pass it on to. Once you get to the last page, just pass in 'submit' and the script will process as per usual.

It's a minor "pass through" change to add.cgi. *everything* else is pretty much built into links.

Postcards.cgi does some extra checking to validate fields, check dates, etc. but it's add routine is just a glorified add.cgi with multiple page pass throughs.

If you don't want to modify add.cgi, you can write a short script that you call instead of add.cgi, which just passes the data back to the next template, then on the last template, just call add.cgi with 'submit'.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Using multiple forms to submit In reply to
Ok, I've been trying to modify add.pm to allow the multiple pages to work, but I'm missing something. I've modified as follows:

Code:


sub handle {
# -------------------------------------------------------------------
# Display either an add form or process an add request.
#
if ($CFG->{user_required} and ! $USER) {
print $IN->redirect( Links::redirect_login_url ('add') );
return;
}


# We are processing an add request.
if ($IN->param('pg1')) {
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'user_add_link', \&add_link, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('pg2', $results);
}
}


if ($IN->param('pg2')) {
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'user_add_link', \&add_link, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('pg3', $results);
}
}




......and of course the rest goes on for several more pages like above


Of course I'm including pg1.html in the add.cgi template directory. If I separate the basic fields, ie Title, URL, etc.. and use several pages like this, it works but reports the error of not being able to submit without "whatever" and continues to scroll through. If I set it up with all of the basic fields on the first page, it reverts back to page 1 after hitting submit and its added to the database.

The additional pages I've included hidden fields to record the values as they are passed along, but I'm getting no where reall fast right now.

Thanks for any info,


Perl Hopefull
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
I think I got it.....I removed the lines below in red and it seems to work so far...

Code:
# We are processing an add request.
if ($IN->param('pg1')) {
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'user_add_link', \&add_link, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('pg2', $results);
}
}


if ($IN->param('pg2')) {
my $results = GT::Plugins->dispatch ($CFG->{admin_root_path} . '/Plugins', 'user_add_link', \&add_link, {});
if (defined $results->{error}) {
print $IN->header();
print Links::SiteHTML::display ('pg3', $results);
}
}
Perl Hopefull
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
As I continue to add more and more fields, (getting into several hundred fields), it's beginning to become very cumbersome transcribing every single previous field entered into a hidden field to pass along values. Isn't there some way to do this without listing every single one up until it's actually submitted?

I've used a simple cgi script in the past that takes the data entered and passes it into the next form page by using a simple command, {hidden} added to each form. This command then translates all the hidden values to the final form at the end for review. The script is very small and only one page, but I can't figure out how to integrate something like this into Links, although it would be great for large forms.

Any takers?
Perl Hopefull
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
ahhhhh! I just now realized that this is printing the entire previous page on the next page giving two screens as you scroll downwards!!!
Quote Reply
Re: [stilton] Using multiple forms to submit In reply to
That was nice. huh. :-)

Nakul Goyal
www.nakulgoyal.com
SEO, SEP, SEM and Link Building Expert
>> Nakul Goyal (SEO, Link Building Expert)
Web Site Promotion
Tips 'n' Tricks
SEO News