I'd like to choose the value of a radio button according to the value of a PHP variable defined in the page where the Machform form is embedded.
How do I need to modify view-functions.php file?
Thanks!
Mike
Started 1 year ago by msfbiz | 7 posts |
I'd like to choose the value of a radio button according to the value of a PHP variable defined in the page where the Machform form is embedded.
How do I need to modify view-functions.php file?
Thanks!
Mike
Are you using the advanced form code or the standard (iframe)?
Also, is the PHP variable being passed as URL parameter?
MachForm Founder
I'm using the advanced form code.
No, the PHP variable is NOT passed as a URL parameter, it's defined in the PHP code of the page at the top.
Ok, so let say you have a radio button like this:
<input id="element_2_1" name="element_2" class="element radio" type="radio" value="1" />
<label class="choice" for="element_2_1">First option</label>
<input id="element_2_2" name="element_2" class="element radio" type="radio" value="2" />
<label class="choice" for="element_2_2">Second option</label>
<input id="element_2_3" name="element_2" class="element radio" type="radio" value="3" />
and your form code + variable is like this:
<?php
$my_radio = 2;
require("/home/machform/machform.php");
$mf_param['form_id'] = 159;
$mf_param['base_path'] = 'http://example.com/machform/';
display_machform($mf_param);
?>
and our goal is to choose the second radio button (id = 2) when the value of $my_radio variable is 2 as well.
So, all you need to do is to edit your "includes/view-functions.php" file.
Search around line 493 for this code:
foreach ($element->options as $option){
exactly below that code, add this:
if($option->id == 2 && $GLOBALS['my_radio'] == 1){
$option->is_default = true;
}
that should do it.
MachForm Founder
Great, thanks!!!
I have tried the code, but it's not working.
Also shouldn't it be
if($option->id == 2 && $GLOBALS['my_radio'] == 2){
$option->is_default = true;
}
since we want the radio value 2 to be selected?
In any case, I've tried with both == 1 and ==2 but couldn't get it to work.
Can you send me your file and the URL to your form please?
Send to: customer.service [at] appnitro.com
I'll check it.
MachForm Founder
You must log in to post.