yellowled Posted May 28, 2014 Share Posted May 28, 2014 In a project, I have a lot of links which all lead to the same form. Every link is asscociated with an object which has a unique id. I need to set the value of one field in said form depending on which link has been clicked so that the recipient of the emails sent by the form knows which object they inquiry is related to. Sometimes these objects may be on a single page, sometime multiple links on the same page, so the association needs to be with the link, not with the page. I know how to do this using JS and cookies, but I'd rather not use that if possible. Is there a way to maybe use $session for this? If so, how do I set a session variable based on “if a link is clicked”? is that even possible? Link to comment Share on other sites More sharing options...
Soma Posted May 28, 2014 Share Posted May 28, 2014 Is this using FormBuilder? Link to comment Share on other sites More sharing options...
Nico Knoll Posted May 28, 2014 Share Posted May 28, 2014 Couldn't you just add something like ?link=abc to the link url? (You still could use $session->redirect afterwards to hide it) Like: <a href="/a-page/?link=abc"> and on /a-page/: $session->set('redirect', $input->get->link); $session->redirect($page->url); 1 Link to comment Share on other sites More sharing options...
yellowled Posted May 28, 2014 Author Share Posted May 28, 2014 No, it's not using FormBuilder. I'll test Nico's code, thanks for that. Link to comment Share on other sites More sharing options...
yellowled Posted May 28, 2014 Author Share Posted May 28, 2014 and on /a-page/: $session->set('redirect', $input->get->link); $session->redirect($page->url); That does bascially work fine, but the redirect doesn't seem to be a good idea. Chrome gives me a warning that the page has a redirect (Duh!) and refuses to load it (after trying to load for quite some time). So it's a dead end with the redirect. However, it does work well without the redirect. I'm kind of okay with the extra URL segment there, but of course, if anybody has another idea how to get rid of it … Link to comment Share on other sites More sharing options...
MadeMyDay Posted May 28, 2014 Share Posted May 28, 2014 Don't really understand the question (or the problem ). Why not add a parameter to each link and react on that on the form page? <a href="form.php?formid=82828"> form page: $formid = $input->get->formid; // get the title of the page or whatever $myValue = $pages->get($formid)->title; form: <input type="hidden" value="<?= $myvalue ?>" name="Referrer"> Or do I misunderstand the question? 1 Link to comment Share on other sites More sharing options...
yellowled Posted May 28, 2014 Author Share Posted May 28, 2014 Or do I misunderstand the question? That part is already done and working like a charm. Nico's code was (I think) supposed to redirect from e.g. /contact/?id=1 to just /contact/ (while still submitting the 1 to the $session variable) to keep the URL nice and clean. But as I tested it, I noticed it throws an error message in the browser because of the redirect. Link to comment Share on other sites More sharing options...
MadeMyDay Posted May 28, 2014 Share Posted May 28, 2014 So I still don't understand what you want to do ;-) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now