[FX.php List] A php question
John Funk
jfunk at criticalsolution.com
Mon Mar 9 11:46:40 MDT 2009
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
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20090309/bc5f3bba/attachment.html
More information about the FX.php_List
mailing list