[FX.php List] A php question

Derrick Fogle derrick at fogles.net
Mon Mar 9 12:12:39 MDT 2009


You're not having any trouble displaying the checkmark, are you?  
Previous emails indicated that the problem was that, when submitting  
the form, when the box is NOT checked, the name-value pair never gets  
submitted to the input processing page (which throws off your field  
indexing).

The failure of the form to submit a name when there is no value  
checked is "normal" HTML. The only real work-around is to hard-code as  
Leo suggested; if there is no value, then you know the box was un- 
checked, so you can submit '' as the value for the field. If it was  
checked, then everything is there and works correctly.

This still fails to solve the indexing issue though, doesn't it?  
You'll have to implement some alternative logic to handle the field  
index issue. Unfortunately, I don't have any great ideas on that.


On Mar 9, 2009, at 12:46 PM, John Funk wrote:

> 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 />";
> ?>
>
> 	• looks for a specific string
> 	• if there show a checked box pass the input name as DealerType1
> 	• if NOT there show an UNchecked box pass the input name as  
> DealerType1
>
> 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


Derrick



More information about the FX.php_List mailing list