an if statement for a checkbox

Heeb 18 Nov, 2012
Hi

i d'like to have an if statement in the form for a checkbox. (http://www.x-mascard.ch/stadtpolizei/)
So when i check the box, it should send a defined text. When its uncheckd, it should send the text in the "Nachricht" field. How can i do this? My solutions do not work😟

an if statement for a checkbox image 1
an if statement for a checkbox image 2


Thanks in advance and best regards
Patrik
GreyHead 19 Nov, 2012
Hi Heeb,

The $_POST is not needed. Please try this:
<?php
if ( isset($form->data['input_checkbox_11']) ) {
  $form->data['input_textarea_5'] = 'Standart';
} else {
  $form->data['input_textarea_5'] = $form->data['Nachricht'];
}
?>

Bob
Heeb 19 Nov, 2012
Hi Bob.

Thx for your solution. In the Confirmation Page (in the debugger) i can see that the $form->data['input_checkbox_11'] is passed correct but it seems as the PHP code is ignored. The value in the $form->data['input_textarea_5'] is always "standart" all the same checked or not.
Is it an order problem from the actions?


Patrik
GreyHead 19 Nov, 2012
Hi Patrik,

I missed a ) from the 'if' line in the code - now fixed. If that doesn't solve it please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.

Note: if you are using the Easy Wizard you can turn on Debug on the Others tab.

Bob
Heeb 19 Nov, 2012
i ve fixed the missing ) from the "if" line in the code.
You can fill out the form Link, i ve dragged a debugger action on the submit event. After you can see the debuggers result on the confirmation Page. I have the same template code for the email like on the confirmation page.

Thx for your help!

Patrik
GreyHead 19 Nov, 2012
Hi Patrik,

The 'ghost' setting is on I think so the isset() check isn't enough. Please try:
<?php
if ( isset($form->data['input_checkbox_11']) && $form->data['input_checkbox_11'] ) {
  $form->data['input_textarea_5'] = 'Standart';
} else {
  $form->data['input_textarea_5'] = $form->data['Nachricht'];
}
?>

Bob
Heeb 19 Nov, 2012
Very well that works, thank you very much!
Now i've buy the form for 3 domains and i will u donate a beer.

Next project is to include jFormer script to add easier more dynamic e-mail recipients. Maybe i need you help again in an other post.🙂

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