I have been working on a form for some time and am baffled about why it is not doing what I think it is suppose to do.
By the way, it is a form that I have inherited and part of a CMS so I am limited about how much I can change it by the application.
The situation is that the form (which is using the output buffer)has a
Almost forgot, this is a complex login form that has an IP Address
check in it. If the "expected" IP address is different that the one
stored in the database, it loops back and adds a test for the users
birthdate which does a different database lookup. This one form is
used to manage both conditions.
The form was originally designed to use a text box and the request was
to replace it with a drop down because his users didn't follow the
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 placed several print_r statements to see what is going on and
the very last I have just after the submit and just after the
ob_get_content and just before the return and $_POST['birthdate'] has
the correct value in it but apparently the script compare function
isn't see it for some reason. If, like I say, I run the input again,
it works fine?
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
at all no matter how many times you run it. I would really appreciate
someone who might have done something like this and solved it to give
me an idea of where I need to go with it.
Many thanks for your attention,