WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Contact Form 7 form that needs to redirect to specific pages depending on how the user arrived at the form. I'm storing the URL they need to be redirected to using localStorage and I'm trying to figure out how to tell contact form 7 this stored URL to use for redirection when the user clicks "Submit".

i.e. the basic redirection method within CF7's "Additional Settings" is:

on_sent_ok: "location.replace('http://www.YOURSITE.com');"

and I'm trying to set the URL using javascript:

var newUrl = localStorage.getItem('storedurl');}

on_sent_ok: "location.replace( newUrl );"}

Doesn't have to call localStorage from within CF7, it could just call in a variable that's been set globally. But I can't get either to work.


share|improve this question

Turns out there were some variable problems with that code. I've changed it to this and its working now!

on_sent_ok: "location.replace( localStorage.getItem('storedurl') );"

Where storedurl is the key for the stored URL in local storage.

Not sure why the variables weren't working but that's a story for another day!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.