Undefined index error

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 25, 2012   (RSS)

Re: [nmsinc] Undefined index error

By Dave - March 25, 2012

Hi nmsinc,

Checkboxes are the only kind of html form field that don't submit anything at all if they're not checked. What I usually do is use a hidden field field like this:

<input type="hidden" name="view_map" value="0" />
<input type="checkbox" name="view_map" value="1" />

If you have two fields with the same name then the value of the last one is used. So if checked you'll get view_map=1 and with unchecked you'll get view_map=0

Another trick is to use @ which suppresses errors and warnings in php. So instead of $_REQUEST['view_map'] use @$_REQUEST['view_map']

Also, note that we use $_REQUEST, which has both $_GET and $_POST in it, which is why changing $_POST didn't make a difference.

Hope that helps, either of the above two solutions should fix it. Let me know if you have any other problems.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Undefined index error

By nmsinc - March 25, 2012

The hidden fields worked perfect - thanks Dave!
nmsinc