NYCPHP Meetup

NYPHP.org

[nycphp-talk] Form not working as expected

Rolan Yang rolan at omnistep.com
Fri Mar 14 01:30:36 EDT 2008


Rolan Yang wrote:
> mikesz at qualityadvantages.com wrote:
>> Hello and Warm Greetings,
>>
>> I have a form that I have been asked to modify and thought it was a
>> straight forward and simple MOD but it seems to have some a condition
>> that I didn't count on when I agreed to make the change and I need
>> some advice.
>> =instructions for formatting most of the time, even with an example
>> provided. The form does a lookup to see if the birthdate matches the
>> one that is stored in the database. In the lookup, it compares the
>> value in $_POST['birthdate'] with the value in the database. The text
>> box works fine if you enter the correct yyyy-mm-dd format.
>>
>> The replacement dropdown has three $_POST values very creatively
>> assigned, $_POST['year'],$_POST['month'],$_POST['day']. To compensate
>> for the replacement of $_POST['birthdate'] and try to make the change
>> transparent to the rest of the script I generated it manually in a
>> hidden field (I actually thought this one WAS creative until I
>> discovered that it didn't work as I expected, lol),
>>
>> <input type="hidden"  value="<?=$_POST['year'] . "-" . 
>> $_POST['month'] . "-" . $_POST['day'];?>" name="birthdate">
>>
>> The problem, as you may have already guessed is that
>> $_POST['birthdate'] gets no date values until AFTER the submit button
>> and that is too late for it to do its database compare so it fails. If
>> you rerun the form entry a second time the script works, no problem
>> but the first time through nada.
>> ...
>> I have tried replacing the $_POST['birthdate'] with a variable
>> $birthdate that I generate manually with the correct data and pass it
>> to the diff function but that breaks the script so that it doesn't work
>>
>>   
>
Correction:

if ($POST['year']) {
   
$_POST['birthdate']=$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
}




More information about the talk mailing list