Forums

Custom Code on Submit

SeniorDingDong 08 Aug, 2014
Hey,

I am trying to run some custom code like this befor I redirect the form to another page:

<?php
$_POST['EMAIL'] = $_POST['emails'];
?>


I tried using a custom code block in "on submit". This code does not seem to be run or It is the wrong place to alter the $_POST Variables. Where would I have to do this?

Thanks
Martin
GreyHead 09 Aug, 2014
Hi Martin,

I would expect that to work OK. But what exactly are you trying to do here? The $_POST array isn't passed on anywhere by PHP.

Bob
GreyHead 09 Aug, 2014
Hi Martin,

Thanks for the PM, I think that the problem probably is that, unlike CFv3, ChronoForms v5 only reads the $_POST array once when the form is first submitted.

In CFv5 if you want to pass data between actions you need to add it to the $form->data array e.g.
<?php
. . .
$form->data['SHASign'] = sha1($str);
?>
You can then pick it up later using either $form->data['SHASign'] in PHP or {SHASign} in HTML (not supported everywhere).

Bob
SeniorDingDong 09 Aug, 2014
Hey, thanks for the quick reply.

I tried
echo "a: ".$form->data['EMAIL'];
echo  "b: ".$form->data['emails'];
$form->data['EMAIL'] = $form->data['emails'];
echo "c: ".$form->data['EMAIL'];
echo  "d: ".$form->data['emails'];


and it results in the correct output:
a:
b: example@example.com
c: example@example.com
d: example@example.com

So your answer seems to be working. Great.

My next problem is that the array is not passed by the redirect plugin.

After redirect my POST Array still only contains:
emails example@example.com
EMAIL

Thanks.
Martin
GreyHead 09 Aug, 2014
Answer
Hi Martin,

I still have no idea what you are actually trying to achieve here. Ther ReDirect action doesn't pass the $_POST array - nor does anything else.

If whatever you are redirecting to will accept GET then you can add the values to the ReDirect URL. Or if it's another ChronoForm you can use the Data to Session & Session to Data actions.

Bob
SeniorDingDong 09 Aug, 2014
Hey, Thanks for your answer. I had to figure out how to add the values to the URL.
orderID=orderID
amount=amount
currency=currency

did the trick.

Now that its working its time to clean up and turn it into good code :-).

Thanks.
This topic is locked and no more replies can be posted.