Forums

Ghost for Custom Form Check Boxes

jjspelman 13 Jul, 2012
HI All,

Got a question about adding ghost values for a custom form. The emails are, of course, showing field values even when not checked. I saw a post from Bob where he offered an option to create an array from the possible values of the check boxes.

So I have this:

<tr align="left" valign="top">
	<td colspan="2">
		<table width="596" border="0" cellpadding="3" cellspacing="3" class="forms">
			<tbody>
				<tr align="center" valign="top">
					<td width="244" align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Pallet Dispenser"> Pallet dispenser</td>
					<td width="329" align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Bottom Layer Sheet Dispenser">  Bottom layer sheet dispenser</td>
				</tr>
				<tr align="center" valign="top">
					<td align="left" valign="middle"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Tier Sheet Dispenser"> Tier sheet dispenser </td>
					<td align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Discharge Conveyor">  Discharge conveyor (# of loads)<input name="DISCHARGE_CONVEYOR_NUMBER_OF_LOADS" type="text" id="DISCHARGECONVERYLOADS2" size="10"></td>
				</tr>
				<tr align="center" valign="top">
					<td align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Bag Flattener"> Bag flattener </td>
					<td align="left"> </td>
				</tr>
			</tbody>
		</table>
	</td>
</tr>


And added the custom action before the email as such:

<?php
$OPTIONAL_EQUIPMENT = array (
  'Pallet dispenser',
  'Bottom layer sheet dispenser',
  'Tier sheet dispenser',
  'Bag flattener',
  'Discharge conveyor (# of loads)'
);
foreach ( $OPTIONAL_EQUIPMENT as $k ) {
  if ( !isset($form->data['OPTIONAL_EQUIPMENT_list_'.$k]) ) {
    $form->data['OPTIONAL_EQUIPMENT_list_'.$k] = '-';
  }
}
?>


This doesn't seem to have the the right solution.

Any thoughts?
GreyHead 13 Jul, 2012
Hi jjspelman,

First, you aren't using array names for the checkbox group so you will only get the last checked item returned. If you want more than one then you need to use an array name="OPTIONAL_EQUIPMENT[]"

Second, your PHP seems to be checking for values in $form->data['OPTIONAL_EQUIPMENT_list_'.$k] which converts, for example, to $form->data['OPTIONAL_EQUIPMENT_list_Pallet dispenser'] and that input doesn't exist in your form.

I would expect that the normal On Submit process with a Handle Array action might do what you need. If the array is completely empty then you may need to add code like this in a custom code action before the Handle Arrays action:
<?php
if ( !count($form->data['OPTIONAL_EQUIPMENT']) {
  $form->data['OPTIONAL_EQUIPMENT'] = array('-');
} 
?>

Bob
jjspelman 26 Jul, 2012
Hi Bob,

Unfortunately I know nothing of PHP. I copied that code from a previous post. So I am not really understanding any mistakes made and their fixes.

If we were to start from scratch with the following code in a custom form:
<tr align="left" valign="top">
   <td colspan="2">
      <table width="596" border="0" cellpadding="3" cellspacing="3" class="forms">
         <tbody>
            <tr align="center" valign="top">
               <td width="244" align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Pallet Dispenser"> Pallet dispenser</td>
               <td width="329" align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Bottom Layer Sheet Dispenser">  Bottom layer sheet dispenser</td>
            </tr>
            <tr align="center" valign="top">
               <td align="left" valign="middle"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Tier Sheet Dispenser"> Tier sheet dispenser </td>
               <td align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Discharge Conveyor">  Discharge conveyor (# of loads)<input name="DISCHARGE_CONVEYOR_NUMBER_OF_LOADS" type="text" id="DISCHARGECONVERYLOADS2" size="10"></td>
            </tr>
            <tr align="center" valign="top">
               <td align="left"><input type="checkbox" name="OPTIONAL_EQUIPMENT" value="Bag Flattener"> Bag flattener </td>
               <td align="left"> </td>
            </tr>
         </tbody>
      </table>
   </td>
</tr>


How would I make it so that the form returns nothing if the user doesn't check anything?

On another note, the client is telling me that this is also happening with radio groups. If the user chooses no radio button, the field value is returned. I was thinking if I added an "N/A" button, with a value of "Not Applicable", and set that to be pre-checked, that might solve that problem. Your thoughts?
jjspelman 01 Aug, 2012
Bob, Max,

Any chance of addressing this? Client is asking, of course. I am just not a PHP guy, wondering if the only way to do this would be to build the form within ChronoForms, but that seems like an awful lot of work.

Thanks!

JJ
GreyHead 02 Aug, 2012
Hi JJ,

In CFv4 there is a Replace Nulls option on the Email action Template tab that will do this - scroll down to see it.

You can also add the check with a Custom Code action in the On Submit event.
<?php
$input_array = array(
  'OPTIONAL_EQUIPMENT',
  'BICYCLE_CLIP',
  'GARBAGE_BINS'
);
foreach ( $input_array as $v ) {
  if ( !isset($form->data[$v] ) {
    $form->data[$v] = '';
  }
}
?>
Add extra names to the input array for the checkbox and radio button inputs.

This will set these entries to be blank ''.

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