unchecked checkbox handling in scripts

Use this forum for questions regarding adoption and functionality of OpenEMM

Moderator: moderator

keko
Posts: 3
Joined: Sun Sep 22, 2013 5:34 pm

unchecked checkbox handling in scripts

Post by keko »

hi all,
can anyone give me a hint how to deal with unchecked checkboxes in a script?

I've multiple checkboxes defined in a form such as the one below

Code: Select all

		<div class="chkbox">
			<input type="checkbox" id="addinfo" name="ADDINFO" value="1" >
		</div>
in the script I'm accessing these using the $requestParameters-method:

Code: Select all

#set( $addinfo            = $requestParameters.ADDINFO )
if any of the checkboxes is not checked the script runs into an error state because requestParameters returns with an error

Code: Select all

Error in line 5, column 29: Null reference $requestParameters.ADDINFO.[]
I also tried to use the code below without success

Code: Select all

#set( $addinfo            = $!requestParameters.ADDINFO )

any help is greatly appreciated!

Thanks
maschoff
Site Admin
Posts: 2596
Joined: Thu Aug 03, 2006 10:20 am
Location: Munich, Germany
Contact:

Re: unchecked checkbox handling in scripts

Post by maschoff »

Did you apply bugfix #05 to OpenEMM 2013? (https://sourceforge.net/projects/openem ... /Bugfixes/)
OpenEMM Maintainer
keko
Posts: 3
Joined: Sun Sep 22, 2013 5:34 pm

Re: unchecked checkbox handling in scripts

Post by keko »

thanks for the quick reply!!

yes I've applied that - if I check all checkboxes the script works - it's really just about unchecked ones

I don't have the link at hand but after googling the issue I think the problem is that browsers simply do not send the parameter of checkboxes if it is not checked.
it seems that the hasmap requestParameters reads does not contain the key an runs into an exception (rather than returning some value)

I could not find a way to check if the parameter exists before actually "using" it


EDIT:
here's one of the links that describe that the paramter is actually not sent if the box is not checked

http://stackoverflow.com/questions/1142 ... ts-checked
Hofmann M.
Posts: 22
Joined: Thu Aug 03, 2006 3:18 pm
Location: Ruhpolding, BY, Germany
Contact:

Re: unchecked checkbox handling in scripts

Post by Hofmann M. »

Hi keko,

i'm not sure but i think a have a solution for your problem.

Your input-field don't send a information to your openemm if you don't check the checkbox.
The error is based at the velocitiy-script because your parameter "$addinfo" won't get some request-parameters.

Integrate this line additional for each checkbox:

Code: Select all

<input type="hidden" name="__AGN_DEFAULT_CHECKBOXNAME" value="0">
your example:

Code: Select all

<div class="chkbox">
   <input type="checkbox" id="addinfo" name="ADDINFO" value="1">
   <input type="hidden" name="__AGN_DEFAULT_ADDINFO" value="0">
</div>
This will send the default-value "0" to the OpenEMM and i hope it fix your problem.

Kind regards
Markus
keko
Posts: 3
Joined: Sun Sep 22, 2013 5:34 pm

Re: unchecked checkbox handling in scripts

Post by keko »

thanks a lot Markus,
I'll use that solution with my next mailing

meanwhile I've worked around the problem by using radio-buttons

thanks again
Post Reply