Forums

radiobox problem

nester 12 Nov, 2012
Hello, im completely new to website making and PHP coding, so my problem might seem obvious to you.
Im trying to do a email sending form with a radio box, which has such an option:
em1=statement1
em2=statement2
em3=statement3

then i added custom code event, which has this code:
<?php
if($data['input_radio_0'] == 'em1') 
{$form->data['subject1']='subject number 1'; 
$form->data['mailto']='xxx1@gmail.com';}

if($data['input_radio_0'] == 'em2') 
{$form->data['subject1']='subject number 2';
$form->data['mailto']='xxx2@gmail.com';}

if($data['input_radio_0'] == 'em3') 
{$form->data['subject1']='subject number 3';
$form->data['mailto']='xxx3@rtrtr.com';}
  
?>

then i simply put word subject1 to a Dynamic subject field, and mailto to a Dynamic to field.

But this seems not working and gives an error instead, in which it said that there should be atleast one email to send to.

Can you please give me a hint where am i wrong?

Thanks in advance.
Louisleon 12 Nov, 2012
Hello,

could it be that your custom code is not running before submit?
Else, did you group the radio-boxes? (you should have a group "input_radio_0")
Did you set the right values in the option field of the radio-boxes?
for example: No = False, Yes = em1 etc.

Best regards

LL
nester 12 Nov, 2012
Hello, Louis.
I've placed custom code right in On submit before Email action. But it seems like Action works correctly, because if i use, for example code like this

<?php
if($data['input_radio_0'] == 'em1') 
{$form->data['subject1']='subject number 1';
$form->data['mailto']='xxx1@gmail.com'}
else 
{$form->data['subject1']='subject number 2';
$form->data['mailto']='xxx2@gmail.com'} ?>

It works, but email is always sending on [email]xxx2@gmail.com[/email]
So the problem is in radio box value.
Yes i did group it and, i've set values according to the description 'in value = text'
so i did it like that
em1 = text1
em2 = text2
and so, but the code doesnt recognize these values which i dont know why 😶

And thanks for your reply!
Louisleon 12 Nov, 2012
Hello,

a radio-box can only handle bool values (No/Yes)!
I will have a try later. No time now.

Best regards

LL
nester 13 Nov, 2012
Hello again, seems like i've done it myself, but i have another question connected to radiobox element, which has an option like this:
em1 = text1
em2 = text2

I need a changeable default value for my radiobox, so i made a code like this:

<?php
if ( $form->data['param'] != 'example1' ) 
$form->data['adrfrom'] = 'em1';
?>

(i just used example instead of a real condition so you dont need to care about it)

after that i just placed "adrfrom" (without quotes) in Default value field, but its not working 😟

So i guess there is some other way to work with default value field or it cant be dynamic at all. Can it be that im wrong somewhere?
GreyHead 13 Nov, 2012
Hi nester,

For the email question this line
if($data['input_radio_0'] == 'em1') 
should be
if($form->data['input_radio_0'] == 'em1') 
or better
if ( isset($form->data['input_radio_0']) && $form->data['input_radio_0'] == 'em1') 
which avoids a possible PHP warning if the variable is not defined.

Please see this FAQ for more on sending emails to different addresses.

You can't set a dynamic default value for a radio box (or any other input) directly in the element configuration. You can set a value in the $form->data array that ChronoForms will then apply assuming that Republish Data is turned on in the Show HTML action (it is by default).

Leave the Default Value box empty and add the value like this:
<?php
if ( isset($form->data['param']) && $form->data['param'] != 'example1' ) {
  $form->data['radio_box_name'] = 'em1';
}
?>

Bob
nester 14 Nov, 2012
It seems to be working now, thank you very much, Bob! 😀
And also thanks Louis!

Chronoforms surely rocks, dont know what would i do without it.
This topic is locked and no more replies can be posted.