[FX.php List] A php question
John Funk
jfunk at criticalsolution.com
Mon Mar 9 12:19:46 MDT 2009
Yes I see, I am switching to radio boxes.
Thanks for all your effort.
On 3/9/09 1:05 PM, "Leo R. Lundgren" <leo at finalresort.org> wrote:
> Unless I totally misunderstand your problem, then no; Your problem/what you
> want to do isn't to get a checkbox with the name DealerType1 submitted even if
> it is unchecked. Unchecked checkboxes are simply not POSTed at all, and this
> is the expected behaviour. To
> quote http://www.w3.org/TR/html401/interact/forms.html#checkbox , "When a form
> is submitted, only "on" checkbox controls can become successful."
>
> So, you should expect the following form a checkbox:
> - If it is checked, you will recieve it as part of the POST.
> - If it is *not* checked, you will not recieve it as part of the POST.
>
> I think it's more a problem of how you handle this fact in your business
> logic. I don't fully understand what you want to accomplish with showing a
> checkbox for something that you apparently still want to recieve the same
> value for nomatter what the checkbox status is.
>
>
> 9 mar 2009 kl. 18.46 skrev John Funk:
>
>> Leo,
>> I see your point but I think my problem is getting the input name posted
>> from the form if the check box is not set.
>> I am only checking if a specfic text in in the field, I do not care if it is
>> empty, infact if it is empty my logic should show an unchecked input field.
>> So it is this part that is causing me problems:
>>
>> <?php
>> if ($DealerType1 =='Stand-Alone Single')
>> echo "<input name= 'DealerType1' type='checkbox' value='Stand-Alone Single'
>> checked />";
>> else
>> echo "<input name= 'DealerType1' type='checkbox' value='Stand-Alone Single'
>> unchecked />";
>> ?>
>>
>>
>> 1. looks for a specific string
>> 2. if there show a checked box pass the input name as DealerType1
>> 3. if NOT there show an UNchecked box pass the input name as DealerType1
>> 4.
>>
>> John
>>
>>
>>
>> On 3/9/09 12:10 PM, "Leo R. Lundgren" <leo at finalresort.org> wrote:
>>
>>
>>> Damn me, I was too quick when editing that. This code is what I meant to
>>> paste, of course:
>>>
>>> $DealerType1 = (isset($_REQUEST['DealerType1']) ? $_REQUEST['DealerType1']
>>> : '0');
>>> $request->AddDBParam('DealerType1', $DealerType1);
>>>
>>> Sorry :-/
>>>
>>>
>>> 9 mar 2009 kl. 18.08 skrev Leo R. Lundgren:
>>>
>>>
>>>> Well, just as with any input validation, you must be prepared for and
>>>> handle gracefully the situation where you don't get the data that you are
>>>> expecting from the client. One case of that is getting no data at all.
>>>>
>>>> To cut it short, one way to solve your problem is to make sure that if you
>>>> don't get a value at all, you place a default value in the variable you are
>>>> working with. For example:
>>>>
>>>> $DealerType1 = (isset($_REQUEST['DealerType1']) ? $_REQUEST['DealerType1']
>>>> : '0');
>>>> $request->AddDBParam('DealerType1', $_REQUEST["DealerType1"]);
>>>>
>>>> As I see it, this is only tip of the iceberg for a discussion of best
>>>> practices regarding input handling. But it should be enough to solve the
>>>> problem :)
>>>>
>>>>
>>>> 9 mar 2009 kl. 17.44 skrev John Funk:
>>>>
>>>>
>>>>> I have a survey form that gets data from existing records, shows the data
>>>>> on form with check boxes. When submitted, edits the FMm data.
>>>>>
>>>>> When building and testing the site all worked well. This morning I am
>>>>> getting index errors on the edit page because on check boxes that are NOT
>>>>> checked, do not pass the input name (or data) to the post.
>>>>>
>>>>> Here is my logic on each check box:
>>>>>
>>>>> I get the data using a normal query:
>>>>> $DealerType1=$record['DealerType1'][0];
>>>>>
>>>>> I how the data in a form:
>>>>>
>>>>> <?php
>>>>> if ($DealerType1 =='Stand-Alone Single')
>>>>> echo "<input name= 'DealerType1' type='checkbox' value='Stand-Alone
>>>>> Single' checked />";
>>>>> else
>>>>> echo "<input name= 'DealerType1' type='checkbox' value='Stand-Alone
>>>>> Single' unchecked />";
>>>>> ?>
>>>>> A stand-alone business with a single location<br>
>>>>>
>>>>>
>>>>> In my edit.php file that the form calls, this is how I am getting the
>>>>> data:
>>>>>
>>>>> $request->AddDBParam('DealerType1', $_REQUEST["DealerType1"]);
>>>>>
>>>>>
>>>>> What am I doing wrong? This is an iis web server.
>>>>>
>>>>> John
>>>>>
>>>>> _______________________________________________
>>>>> FX.php_List mailing list
>>>>> FX.php_List at mail.iviking.org
>>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20090309/e13a5d1a/attachment.html
More information about the FX.php_List
mailing list