[Cartoweb-users] Problem with Checkboxes
Oliver Christen
oliver.christen at camptocamp.com
Thu Sep 13 08:27:06 EDT 2007
well, checkbox (as radiobutton i think) are a bit special as, if you dont
set a value, it will return a boolean which may or may not be "translated"
into a "on", "1" or "true" string when trying to print it.
so the safest way is to simply set a value="something" in the checkbox and
when trying to print the content you should get exactly that "something", so
your this->p1 will be set with an expectected value
this->p1 = isset($request['prod1']) ? true : false;
should work also, as if the checkbox is not checked, it will simply not be
in $_REQUEST
when you dont really know whats appening and what is and is not returned,
doing a print_r($_REQUEST) help a lot to see whats going on
regards
Oliver
> Hi,
>
> hm.... I really forgot that :-/ Very stupid error, I know...
>
> But I have another question regarding the checkboxes. The line
>
> this->p1 = isset($request['prod1']) ? $request['prod1'] : '';
>
> returns always an empty string, even if the checkbox has been checked.
> Is there also problem with my syntax in cartoclient.tpl?
>
> {if $products_active|default:''}
> <p><b>Show all Companies for a special Product</b></p>
> Products:<br />
> <input type="checkbox" id="prod1"
> name="Brotgetreide"/>Brotgetreide<br />
> <input type="checkbox" id="prod2" name="Butter"/>Butter<br />
> <input type="checkbox" id="prod3" name="Eier"/>Eier<br />
> <input type="checkbox" id="prod4" name="Milch"/>Milch<br />
> {/if}
>
> I saw, that there are also checkboxes in the demoEdit sample project,
> but I do not really understand it and was therefore not able to adapt it
> to my needs.
>
> Thanks in Advance
> Carolin
>
> Oliver Christen wrote:
>> Hi
>>
>> well, have you defined the constants you use ?
>> because the error message say you did not.
>>
>> const PROD1 = 'prod1';
>> ...
>>
>> if you try to directly use the checkbox name, does it work ?
>>
>> this->p1 = isset($request['prod1']) ? $request['prod1'] : '';
>>
>> regards
>> Oliver
>>
>>> Hi all,
>>>
>>> I try to write a plugin, which executes depending on a checkbox
>>> selection in the Navigation Tab. Therefore, I add to cartoclient.tpl:
>>>
>>> {if $products_active|default:''}
>>> <p><b>Show all Companies for a special Product</b></p>
>>> Products:<br />
>>> <input type="checkbox" id="prod1"
>>> name="Brotgetreide"/>Brotgetreide<br />
>>> <input type="checkbox" id="prod2" name="Butter"/>Butter<br />
>>> <input type="checkbox" id="prod3" name="Eier"/>Eier<br />
>>> <input type="checkbox" id="prod4" name="Milch"/>Milch<br />
>>> {/if}
>>>
>>> This works perfect. But now, if I try to read out, which checkbox is
>>> activated, I use:
>>>
>>> $this->p1 = isset($request[self::PROD1]) ?
>>> $request[self::PROD1] : '';
>>> $this->p2 = isset($request[self::PROD2]) ?
>>> $request[self::PROD2] : '';
>>> $this->p3 = isset($request[self::PROD3]) ?
>>> $request[self::PROD3] : '';
>>> $this->p4 = isset($request[self::PROD4]) ?
>>> $request[self::PROD4] : '';
>>>
>>> in the HttpHandlePostRequest method of the plugin. This leads to the
>>> following error message:
>>>
>>> Fatal error: Undefined class constant 'PROD1' in
>>> C:\wamp\www\cartoweb3\projects\gis-lag\plugins\products\client\ClientProducts.php
>>>
>>> on line 26
>>>
>>> I think, I use the wrong method to read the checkboxes, but I cannot
>>> find any example how to do it the right way. Does anybody have an idea?
>>>
>>> Thanks in Advance
>>> Carolin
>>>
>>> --
>>> Carolin Latze
>>> Research Assistant
>>>
>>> Department of Computer Science
>>> Boulevard de Pérolles 90
>>> CH-1700 Fribourg
>>>
>>> phone: +41 26 300 83 30
>>>
>>>
>>> _______________________________________________
>>> Cartoweb-users mailing list
>>> Cartoweb-users at lists.maptools.org
>>> http://lists.maptools.org/mailman/listinfo/cartoweb-users
>>>
>>
>
> --
> Carolin Latze
> Research Assistant
>
> Department of Computer Science
> Boulevard de Pérolles 90
> CH-1700 Fribourg
>
> phone: +41 26 300 83 30
>
>
> _______________________________________________
> Cartoweb-users mailing list
> Cartoweb-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-users
>
More information about the Cartoweb-users
mailing list