Forums

Direct execution of php codes depending on the option of radio button

bcouvin 20 Oct, 2015
Hello,

I just start to use Chronoform since 3 weeks. Could someone give me a help?

Here is my issue:

I would like to have a radio group with 2 options (yes/no). If user selected yes, the php code related to the option "yes" is executed.
If option is "no", another php code is executed.

I would like to avoid to have a button "Submit" in the form, and avoid also to use "Event Switcher" like in a demo. There is one more click compare to the previous scenario.

Could someone give me a tip for that?
Thanks

Bertrand
GreyHead 20 Oct, 2015
Answer
Hi Bertrand,

You will need to add JavaScript to your form so that it is automatically submitted after the radio button is clicked (my best guess is that this will confuse some of your users).

PHP is only used on the server after the form is submitted.If you don't want to use the Event Switcher action to manage the response then you will need to use a Custom Code action and write your own PHP code to do whatever is needed in the two cases.

Bob
bcouvin 21 Oct, 2015
Hello Bob,

Thank you for your advice.
What I wanted to do is to change the usergroupid from a web page.

This scenario (A) works:
1- I created a radio group with 2 options and a submit button in Designer tab / Layout.
2- in Setup tab, I added On submit event the Event Switcher, with the related Custom code in php to change the Usergroupid (php_0 for "radio option" = 0, and php_1 for "radio option" = 1)

This scenario works, this usergroupid changed when submitting the form. I can see the value changed with phpMyAdmin.

The scenario (B), this is what I wanted to do is:
1- I created a radio group with 2 options in Designer tab / Layout. In Designer tab / Event, I added Function Call:
On New Value = 0 of "Radio Buton", call Function_0 who execute a JS_0.
On New Value = 1 of "Radio Buton", call Function_1 who execute a JS_1.
2 - How can I integrate my php csutom codes and where? Designer tab/Custom or Setup tab/CustomCode. Where is the link between my php code and my js?


Thank in advance
Bertrand
This topic is locked and no more replies can be posted.