PHP in radiobutton choices

36 views
Skip to first unread message

EPL

unread,
Dec 11, 2014, 2:06:11 PM12/11/14
to sophie-c...@googlegroups.com
I'm wondering if it is possible to use PHP to reference something in a radiobutton choice. For instance, there is an option to put content "before" the form or "after" that uses PHP to reference a previous variable, but there doesn't seem to be a way to switch the Field Options to "CodeMirror."
Any ideas?

Philipp Mamat

unread,
Dec 17, 2014, 11:20:20 AM12/17/14
to sophie-c...@googlegroups.com
Hi,

I just want to make sure that I understood your question correctly:
In the Content Body you are able to use PHP to set the content programmatically and e.g. access SoPHIE variables. In the Form Config you would like to do the same with the Field Options.

This is possible, but in a less obvious way. It is not possible to write PHP code directly in the Options textarea, but you can set the options on "runtime initialization": On the corresponding tab you will find a script field in which you can set PHP code to be executed just when the form is rendered for each participant. In this script you can access the step api with which you can set the attributes on runtime.

The simplies way is to browse the "Set Runtime Attribute" menu and insert the example code for the field you wish to set. For example to set the "Options" field (your question), you use:
$stepApi->setRuntimeAttribute('formOptionsJson', 'attribute value');

As it happens, this special case is a special case:
The (internal) options data must be set in the JSON notation. You can create a JSON string form any object or PHP (associative) array using the function json_encode. A short example would look like this:

$options = array(
    'valueA' => 'Displayed label for the first option (A)',
    'valueB' => 'The other option',
);
$optionsJson = json_encode($options);
$stepApi->setRuntimeAttribute('formOptionsJson', $optionsJson);

Of course, this example is a little bit boring, because there is no actual dynamic in the options, but it should give you the general idea.

Hope this helps. Please ask if you've got more questions!

Regards,
 Philipp
-- 
Philipp Mamat
Symbic GmbH

Persönlicher Kontakt
Telefon: +49 (0) 541 / 50 79 97-18 | Telefax: -19
Mobil: +49 (0) 176 / 800 144 65 | Mail: philip...@symbic.de
___________________________________________________________
Symbic GmbH | www.symbic.de
Im ICO | Albert-Einstein-Str. 1 | DE-49076 Osnabrück 
Sitz der Gesellschaft: Marktstr. 14 | DE-38315 Hornburg

USt.-IdNr.: DE269573411
Eingetragen im Amtsgericht Braunschweig: HRB 202239
Geschäftsführer: Achim Hendriks, Philipp Mamat
Am 11.12.2014 20:06, schrieb EPL:
I'm wondering if it is possible to use PHP to reference something in a radiobutton choice. For instance, there is an option to put content "before" the form or "after" that uses PHP to reference a previous variable, but there doesn't seem to be a way to switch the Field Options to "CodeMirror."
Any ideas?

--
You received this message because you are subscribed to the Google Groups "SoPHIE Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sophie-communi...@googlegroups.com.
To post to this group, send email to sophie-c...@googlegroups.com.
Visit this group at http://groups.google.com/group/sophie-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/sophie-community/3c4953a2-c28f-468a-a86f-fb1970863842%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages