[FX.php List] A php question

Leo R. Lundgren leo at finalresort.org
Mon Mar 9 12:16:10 MDT 2009


9 mar 2009 kl. 19.12 skrev Derrick Fogle:

> 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.

If you mean the problem that there are errors thrown for non-existing  
indexes, that is taken care of by the isset() check inside the first  
line of the code I pasted.


> 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
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



More information about the FX.php_List mailing list