Not show field name of empty radio/checkbox in email

GreyHead 15 Feb, 2010
Hi kko,

The simplest answer to this is to add a code snippet to the OnSubmit Before box. Becasue checkboxes return nothing if they are not checked ChronoForms doesn't know that {fieldname} refers to a form field at all.
<?php
$check_array = array(
  'field_name_1',
  'field_name_2',
  'field_name_'
);
foreach ( $check_array as $v ) {
  $temp = JRequest::getString($v, '', 'post');
  JRequest::setVar($v, $temp);
}
?>

This will ensure that all the values in $check_array exist in the form results (those that aren't checked will have value of '' (an empty string).

A slightly more sophisticated version might be:
<?php
$check_array = array(
  'field_name_1' => '',
  'field_name_2' => 'No',
  'field_name_' => 'Tuesday'
);
foreach ( $check_array as $k => $v ) {
  $temp = JRequest::getString($k, $v, 'post');
  JRequest::setVar($k, $temp);
}
?>
This will substitute the values from the array for any missing values from the form.

Bob

PS Not tested and may need debugging!
kko 15 Feb, 2010
Thanks, Bob!

I used the first set of code and it works perfectly.
I'm sure the second snippet will come in handy for my future use.

Thanks again for the help. 😀
tedZilla99 16 Mar, 2010
I also used that first snippet of code - thank you!
siliconfarm 31 Mar, 2010
Thanks ! I've used the first one as well and it worked.
platipalapi 07 Apr, 2010
why not using simply :
<?php echo $_POST['checkboxfieldname']; ?> 

?
If checkboxes are ticked, it will display the labels, if not, it'll show nothing !
sitebuildernow 26 Apr, 2010
Thanks! I used the "fancier" code and it worked like a charm - appreciated!!
This topic is locked and no more replies can be posted.