Redirect if Form not Submitted
Posted: 10 October 2008 12:36 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  39
Joined  08-06-2008

I want to know if I can redirect visitors from viewing a template if they haven’t filled in a form.

For example.. Users want to view widget samples page but to view this page you need to fill in a form which redirects you to the widget samples page.

If users try to view the widget samples page without filling in the form, they are redirected back to the form.

How can I do this?

Profile
 
 
Posted: 10 October 2008 01:57 AM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

I’m not 100% sure on this but I guess you could do this in a couple of ways. The first one being if your data is sent from the form using POST then you could check for the existence of such data with say a hidden field to see if the form was sent or not. I say a hidden field as otherwise you may have a form where people don’t have to fill all the fields in and they just might not fill in the one you are checking against wink

The other way although one which people could abuse if they know it would be to send along (depends on what you are using to create your form) a success message tagged onto the end of the URL in the last segment. You could then use a simple {if} structure to see if that word is in the URL or not, so something like this :

Submitted Form

http://www.example.com/samples/thankyou

{if segment_2 == "thankyou"}
<p>Show code here</p>
{if:else}
<p>Sorry please fill out the form by visiting this page here - insert link</p>
{/if}

You could probably also save either a cookie or a session variable on page exit to do the same sort of thing if you are worried about people knowing that will be in the URL and visiting the page without it.

Hope that helps.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 12 October 2008 04:42 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  39
Joined  08-06-2008

Thanks for the feedback. I’ll have to try what you have suggested. What I had in mind was to have some PHP in the template to redirect if they didn’t fill in a form but for some reason this doesn’t work in EE.

Not sure if HTTP_REFERER is the best option but something similar to this. Do you know how to get this to work with EE?

<?php

    
if (!isset($_SERVER['HTTP_REFERER'])) {
        header
("Location: http://www.mysite.com/mypage");
    
}
    
    
?>

Profile
 
 
Posted: 13 October 2008 02:56 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

You may need to place an exit; after the header line in order to get this to work?

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 13 October 2008 04:15 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  39
Joined  08-06-2008

Awesome, that did the trick. Thanks!

Profile
 
 
Posted: 14 October 2008 02:04 AM   [ Ignore ]   [ # 5 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

Excellent news!! grin

Hope it goes well for you.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64912 Total Logged-in Users: 28
Total Topics: 81864 Total Anonymous Users: 18
Total Replies: 440101 Total Guests: 181
Total Posts: 521965    
Members ( View Memberlist )
Newest Members:  bjmohrAqua193Bios Elementmjpoteetguimogranwelshmrcfthenetmonkeybenekwhobutsb