homepage Welcome to WebmasterWorld Guest from 54.204.94.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Redirecting to a confirmation html page once a form is submitted
using form mail
michaeltaylor

5+ Year Member



 
Msg#: 3780727 posted 5:30 pm on Nov 5, 2008 (gmt 0)

Hi,

I've used NMS FormMail to crate an enquiry form which works fine. It has three drop down menu items to choose from. All this works fine and the message gets routed to an email address.

However, here's what I'd like to achieve and I don't know whether it's possible to do this using the FormMail.pl script. When a person selects 'option 1' from the drop down menu and submits it, I want them to be automatically forwarded to the html page that says 'thank you for choosing option 1'. Like wise if they choose 'option 2', I want them to be directed to the html page that says 'thank you for choosing option2' and the same for 'option3'. i hope this makes sense!

If any one can help I'd really appreciate it.

Many thanks in advance.

Michael

 

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3780727 posted 7:24 pm on Nov 5, 2008 (gmt 0)

I don't know the script, but in general, that could easily be achieved by just adding an if-condition to the submit-part and having the script print a Location-Header, e.g.
if($CGI->param('option') == 1)
{
print "Location: http://www.example.tld/thankyou.htm\n\n";
}

IIRC, the server would see this and, since he's doing the headers, recognize you want a redirect. That of course won't work if the headers have already been printed. If it's not too big, can you post the script and specifics about how the drop down-field is named, which option should result in a redirect etc?

michaeltaylor

5+ Year Member



 
Msg#: 3780727 posted 7:45 pm on Nov 5, 2008 (gmt 0)

It's quite long and no one seems to put such long responses on here. I'm new to this site so don't know if I'm allowed to put so much on!

Should it be OK?

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3780727 posted 8:16 pm on Nov 5, 2008 (gmt 0)

just make sure you have replaced everything (email, domain, passwords!, local server paths etc) relating to your page with example-values and try to describe stuff rather than pointing to an example on your page.

[edited by: phranque at 5:14 am (utc) on Nov. 6, 2008]
[edit reason] please see TOS #24 [webmasterworld.com] [/edit]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3780727 posted 8:29 pm on Nov 5, 2008 (gmt 0)

Just an addition to the the short answer posted above:

If the request was made using HTTP/1.1, the server should return a response Status code of 303-See Other along with the location header. If the request was made using HTTP/0.9 or HTTP/1.0, then a response code of 302-Found should be returned with the location header.

Note that if your site is on name-based shared hsoting, you will not need to test for the HTTP version; Named-based virtual servers are not accessible using HTTP/0.9 or HTTP/1.0. (You may see requests in your logs marked with HTTP/1.0 -- especially from search engine spiders, but these are actual spoofs to indicate that they can handle a downgrade to the HTTP/1.0 protocol if necessary. These are sometimes termed "enhanced HTTP/1.0 clients.")

Reference the Response Status Code section of RFC2616 - Hypertext Transfer Protocol -- HTTP/1.1 [w3.org]

Also, it would be nice if members would "trim" their own script postings down to just the relevant sections when possible, rather than relying on your all-volunteer moderator staff to do so... :)

Jim

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3780727 posted 5:31 am on Nov 6, 2008 (gmt 0)

welcome to WebmasterWorld [webmasterworld.com], Michael!

the relevant code for this shouldn't be very long, so you should just post what is necessary.
find the place where the header is written and figure out how form parameters are stored and accessed.
the rest is easy.

michaeltaylor

5+ Year Member



 
Msg#: 3780727 posted 2:54 pm on Nov 6, 2008 (gmt 0)

Hi Phranque,

I'm so confused now! More than I was!

Here's the code in the form on the html page:

<td><form action="nms_formmail_enquiries.pl" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><input type="hidden" name="recipient" value="enquiries@example.co.uk">
<input type="hidden" name="subject" value="A message from the Website">
<input type="hidden" name="redirect" value="http://www.example.co.uk/thankyou.html">
<table width="113%" border="0" cellpadding="0" cellspacing="0" class="body">
<tr valign="top">
<td class="form">Name:</td>
<td><input type="text" name="realname" size="25"></td>
</tr>
<tr valign="top">
<td colspan="2" class="form"><img src="images/10x10.gif" alt="a" width="10" height="10"></td>
</tr>
<tr valign="top">
<td class="form">Email address:</td>
<td><input name="Email address" type="text" id="Email address" size="25"></td>
</tr>
<tr valign="top">
<td colspan="2" class="form"><img src="images/10x10.gif" alt="a" width="10" height="10"></td>
</tr>
<tr valign="top">
<td class="form">Telephone:</td>
<td><input type="text" name="telephone number" size="25"></td>
</tr>
<tr valign="top">
<td colspan="2" class="form"><img src="images/10x10.gif" alt="a" width="10" height="10"></td>
</tr>
<tr valign="top">
<td class="form">Nature of enquiry:</td>
<td><label>
<select name="nature of enquiry" id="nature of enquiry" onChange="MM_validateForm('Email address','','RisEmail');return document.MM_returnValue">
<option>I run a business in need of support</option>
<option>I am interested in training courses</option>
<option>I am looking for work</option>
</select>
</label></td>
</tr>
<tr valign="top">
<td colspan="2" class="form"><img src="images/10x10.gif" alt="a" width="10" height="10"></td>
</tr>
<tr valign="top">
<td class="form">Message:</td>
<td><textarea name="Enquiry" rows="6" cols="25"></textarea> </td>
</tr>
<tr valign="top">
<td colspan="2"><img src="images/10x10.gif" alt="a" width="10" height="10"></td>
</tr>
<tr valign="top">
<td>&nbsp;</td>
<td align="right"><div align="left">
<input name="submit" type="submit" value="submit">
</div></td>
</tr>
</table></td>
</tr>
</table>
</form></td>

Above is what I currently have on the form but I want to form to redirect to one of three different thank you pages depending on which option the person filling in the form selects.
I run a business in need of support
I am interested in training courses
I am looking for work

And the script is currently FromMail.pl which is too big to put here.
I hope someone can help shed some light.

Many thanks

Michael

[edited by: phranque at 10:33 pm (utc) on Nov. 6, 2008]
[edit reason] exemplified urls [/edit]

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3780727 posted 9:38 am on Nov 7, 2008 (gmt 0)

Assuming you're using the current nms formmailer (and yes, you were very right not to paste it to the forum ... I didn't know the script and the fact that it has inlined modules and weighs in around 75KB), here's how you do it

To make things easier, change your form so that your fields contain only ascii-characters and omit spaces (I like to do that because spaces are converted to + or %20 and you never really know if some cgi-script will decode that in a fieldname or not), e.g. change

<select name="nature of enquiry" id="nature of enquiry" onChange="MM_validateForm('Email address','','RisEmail');return document.MM_returnValue">
<option>I run a business in need of support</option>
<option>I am interested in training courses</option>
<option>I am looking for work</option>
</select>

to

<select name="nature_of_enquiry" id="nature of enquiry" onChange="MM_validateForm('Email address','','RisEmail');return document.MM_returnValue">
<option value="business">I run a business in need of support</option>
<option value="training">I am interested in training courses</option>
<option value="work">I am looking for work</option>
</select>

the values in the option-tags are for easier serverside checking.

Backup your original script so you can always revert when something is not working.
open the script nms_formmail_enquiries.pl, find "sub success_page {" (use your editors find-function, I have it around line 2987). In that function, you will find the following line:

print $self->cgi_object->redirect( $self->{FormConfig}{'redirect'} );

replace that line with the lines between ---cut--- and ---/cut---
---cut---
if(defined $self->{Form}{'nature_of_enquiry'} && $self->{Form}{'nature_of_enquiry'} ne '')
{
print $self->cgi_object->redirect( 'http://www.example.co.uk/thankyou-' . $self->{Form}{'nature_of_enquiry'} . '.html' );
}
else
{
print $self->cgi_object->redirect( $self->{FormConfig}{'redirect'} );
}
---/cut---

of course you will have to adjust the url and this works only if you made the changes to your form that I suggested. You will then need to add the three pages (names according to the option-tags values from above, e.g. http://www.example.co.uk/thankyou-business.html, http://www.example.co.uk/thankyou-training.html and http://www.example.co.uk/thankyou-work.html. That should be it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved