Page 1 of 1

unchecked checkbox handling in scripts

Posted: Sun Sep 22, 2013 6:15 pm
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

Re: unchecked checkbox handling in scripts

Posted: Sun Sep 22, 2013 9:12 pm
by maschoff
Did you apply bugfix #05 to OpenEMM 2013? (https://sourceforge.net/projects/openem ... /Bugfixes/)

Re: unchecked checkbox handling in scripts

Posted: Sun Sep 22, 2013 9:38 pm
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

Re: unchecked checkbox handling in scripts

Posted: Mon Sep 23, 2013 2:14 pm
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

Re: unchecked checkbox handling in scripts

Posted: Mon Sep 23, 2013 2:48 pm
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