Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Stupid question - how do I set a permanent cookie?

Stupid question - how do I set a permanent cookie?

I have a form which when the visitor has completed goes to a thank you page. On loading the thankyou page I need to set a permanent cookie so that when they try and reload the form it redirects them to a sorry, you already submitted page.

I have a cookie set rule - which appears to work now, but the cookie check and redirect rule does not.

I've used Chameleon to do GEO IP and language redirects, but this should be so straightforward, but I can't get it to work.

I'm checking the debug code and getting confused.

Your docs talk about the general principles, but I need a bit of an 'how to'

dontregartha
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Re: Stupid question - how do I set a permanent cookie?

Is there a support area for paying customers? - Not happy right now.

dontregartha
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Re: Stupid question - how do I set a permanent cookie?

Hi Don,

really sorry for the long delay. We don't have a separate support area for paying customers – all users of the software get the same level of service which is generally much more prompt than this. Very sorry about that. You can also e-mail me directly. You will have received my e-mail address with your original order.

In answer to your original support question:

I think that you're asking for the following scenario:

- If the user tries to go to the form page, you want them to be redirected to a different URL if they have already submitted the form

Therefore we could use the following logic:

1 - Detect if the form is being SUBMITTED. You may be able to do this by URL for the "thank you" page, or possibly by detecting various URL parameters or variables in the POST request. (if in the POST request, you'd need to code a snippet of PHP)

2 - If the form is being submitted, allow it to continue but also set a permanent cookie.

3 - Detect if the form is being LOADED, i.e. a page request for the page with the form on it. If so, AND if the permanent cookie is set, then do a redirection to a different page.

Let's assume the following URLs:

www.example.com/form  = the page with the form on it
www.example.com/index.php  = the page that the form submits to with a POST request with the form data in it
Form variables:
option=com_foo
type=submit
category=3
firstname=john
lastname=doe
email= This e-mail address is being protected from spambots. You need JavaScript enabled to view it

To get a list of these variables and the page they submit to, you might need to use a web inspector such as that found in Safari/Chrome, or Firebug on Firefox, or even better a web proxy inspector like Charles.app. You can generally find the page that the form submits to by examining the HTML source of the page with the form on it and looking at the <form> element.

So here's how I would set this up in Chameleon:

Rule 1: This will detect if the form is being submitted, and will set the permanent cookie if it is.
Because the detection of a submitted form may involve POST variables, I suggest using the PHP tab in the Chameleon rule.
a - create a new rule and name it
b - go to the PHP tab and type:

Code:

if ($option == 'com_foo' and $input->get("type") == "submit") return true;

else return false;

$option is already populated with the value of the POST variable for option. But for the "type" POST variable you need to get it using the $input structure.
c - In the Actions tab, in the left column (Succeed actions) use the dropdown to "Set permanent cookie A"
d - Save the rule.

Rule 2: This will detect if the visitor is trying to visit the form page but has already submitted a form. i.e. the URL is that of the form page AND the cookie is already set. The action is to redirect.
a - Create a new rule and name it
b - In the Environment tab set "Page URL" "Starts with" http://www.example.com/form
c - in the Quick Rules tab set "Cookie/Session variable" to "Permanent cookie A"
d - in the Actions tab, in the left column (Succeed actions) select "Next Action" = "Redirect", and select the page from the "Redirect page..." dropdown or enter the URL that you want it to redirect to into the "Redirect url..." box below it.
e - save and test.

Before doing this obviously you'll need to know the info about where the form submits to, and the URL of the page with the form on it. I can assist you to find this if it's on a public server - just let me know the URL of the form page and I can take a look at it.

Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10727
Newest User:
solza2
Members Online:
0
Guests Online:
207

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked