<![CDATA[ eform only accepts integer values for checkboxes - My Forums]]> https://forums.modx.com/thread/?thread=84125 <![CDATA[Re: eform only accepts integer values for checkboxes]]> https://forums.modx.com/thread/84125/eform-only-accepts-integer-values-for-checkboxes#dis-post-464464
[!emailFormUserInfo!]
[!eForm? &eformOnBeforeMailSent=`emailFormUserInfo` &formid=`ContactForm` ... !]

Before the eForm-call, the snippet emailFormUserInfo is loaded. The eForm-call uses &eformOnBeforeMailSent=`emailFormUserInfo`, that activates function emailFormUserInfo from the snippet above before mail is sent.
<?php
function emailFormUserInfo (&$fields) {

	// Checkboxes
	$checkBoxes = array (
		'myCheckbox01' => '[x] some request',
		'myCheckbox02' => '[x] another strange demand',
	);
	foreach (array_keys($checkBoxes) as $checkBox) if (strlen($fields[$checkBox]) > 0) $fields[$checkBox] = $checkBoxes[$checkBox];

	...

	return true;
}
?>
Note, that strlen() of the checkbox's value has to be greater than 0. isset() doesn't work here, it is always true.

I've changed HTML for checkboxes from
<input type="checkbox" name="myCheckbox01" value="[x] some request" eform="some name 01::1"  />
<input type="checkbox" name="myCheckbox02" value="[x] another strange demand" eform="some name 02::1"  />
to
<input type="checkbox" name="myCheckbox01" value="1" eform="some name 01::1"  />
<input type="checkbox" name="myCheckbox02" value="1" eform="some name 02::1"  />
by replacing strings with integers.

Surely, this issue can be fixed much more elegant. At least, I was glad to have the forms working again and my customer didn't explode.
Every form with a mandatory checkbox and string value probably won't work anymore.]]>
mr.odo Apr 26, 2013, 01:08 PM https://forums.modx.com/thread/84125/eform-only-accepts-integer-values-for-checkboxes#dis-post-464464
<![CDATA[eform only accepts integer values for checkboxes]]> https://forums.modx.com/thread/84125/eform-only-accepts-integer-values-for-checkboxes#dis-post-464344 I recently made an update from 1.0.4 to 1.0.9 on a site with many forms based on eform. All forms have many checkboxes with strings as values. They all don't work anymore. If the form is submitted, validation throws a ef_failed_default => "Incorrect value"; in my language (german).

I don't use name="myValues[]", I have just defined many separate input tags with different names.

If I replace the value with an integer, validation works as expected. I could change the values to integers and replace the contents in eformOnBeforeMailSent, but this would be a big amount of work.

Anyone an idea? smiley

Thx in advance.

PS: An Update to 1.0.10 didn't help.
PPS: On 1.0.8 upgrades, everything is fine.]]>
mr.odo Apr 25, 2013, 08:58 AM https://forums.modx.com/thread/84125/eform-only-accepts-integer-values-for-checkboxes#dis-post-464344