Pass variable to redirect url?

?
Guest 10 Mar, 2008
Hi,

Is there any way to pass a variable from a chronoform submission into the redirect url?

Basically I have a database which contains parts. When viewing the details of a part you can click a link to view associated images. This link passes a part_id variable to a further database query results page which shows any images with the required part_id.

At the bottom of the associated images page is an "add image" Chronoform. One of the fields in this form is set to hidden and is autofilled using a GET command to pull in the part_id value that originally created the page view. It works fine when you first view the page, the part_id is correctly inserted into the chronoform so any submissions will then be tied to the correct part_id.

Once the form has been submitted I want to return to the original query result showing the list of images again (with the new added image at the bottom). To do this I need the part_id variable appending to the redirect url.

I can get the query results displaying again without the part_id variable, as the results array I am using is not cleared during this process. However both the POST and GET arrays seem to be wiped and the original part_id value resets to zero, it doesn't keep the original passed part_id value. Any further submissions are now tied to part_id=0.

So am I trying to do something that isn't possible, or can I enter something into the redirect url option that pulls in the POST data for part_id and appends it to the url (before it all gets cleared during submission).

I'm not a php wizard by a long shot and need some help but even a few pointers in the right direction would be appreciated, I've tried everything that I can think of with my limited knowledge.

ps I do intend to buy a license without question, whether this setup ends up in the production site or not. It's a very neat tool that has a lot more possibilities than the form management tool I've used for the past couple of years. I only got the trial version last night so am still playing with it!<br><br>Post edited by: haweb, at: 2008/03/10 00:51
GreyHead 10 Mar, 2008
Hi haweb,

You can rewrite the redirect url in ChronoForms with a little code. In Joomla 1.0.x you need to change $rows[0]->redirecturl so, assuming that you have a base url in there you could do:
<?php
$rows[0]->redirecturl .= "&part_id=".$_POST'[part_id'];
?>
That should do it. Probably the safest place to put this code is in the 'OnSubmit after mail' box.

Bob

Bob
?
Guest 10 Mar, 2008
Hi Bob,

Thanks for the quick answer. I'm using J1.5 with Chronoforms 2.5 J1.5 RC2.

I tried the code anyway but it didn't work in the On Submit (before email) box. I didn't get the "&part_id=" bit or the value. This form is not set to send any emails so maybe that's why. It just uploads images into a folder and a few fields of text into a table.

Anyway this code:

$rows[0]->redirecturl .= "&part_id=".JRequest::getVar('part_id','','post', 'int', 0 );


works if I put it directly into chronocontact.php in the middle of the "* Redirect the page if requested" part. It does nothing if I put it in the On Submit (before email) box but at least it's a start.

Of course it ruins the component for any further use, although that doesn't matter at the moment as it's doing all it needs to do for now.

Is there a less drastic solution?

Cheers for getting me this far anyway, problem solved!

Chris
GreyHead 10 Mar, 2008
Hi haweb,

If it works in the main ChronoForms code then it 'should' work in any of the main input boxes. (Effectively you can add code in - the HTML code, the OnSubmit before, the OnSubmit after, and the Email template boxes. The only difference is where it is in the processing sequence.)

You will need php tags (as in my example) and sometimes you need global declarations, but not for JRequest.

I can't see any other reason why it wouldn't work. I used essentially the same code for a client a few days ago.

Bob
?
Guest 12 Mar, 2008
Thanks for that Bob,

I'll give it another try in the option boxes and see if I can get anything showing up. I did use php tags, but didn't try any of the other options, just the on submit (before email). Plus it was a late night so I'll make my excuses in advance!

Chris
?
Guest 12 Mar, 2008
Yes it works fine when I put it in the On Submit (after email) box. I suppose if I'd read your first email properly I'd have seen that was where you told me to put it, not in the (before email) box...Sorry about that!

Thanks again for your help.
This topic is locked and no more replies can be posted.