Jump to content

Recommended Posts

... and grabbing it via $_POST['FieldName']

 

When I do this:

 

$CurDate = date("m/d/Y");

 

<input type="hidden" name="SysDate" value="<?php echo $CurDate ?>" />

 

so the hidden contains: 01/09/2009

 

Then I grab it on the next page like this:

 

$pSysDate = $_POST["SysDate"];

 

But when I echo it out it renders: Friday, January 09, 2009 9:07:13 AM

 

AHHHHHHHHHHHHHHHHHHHHH, I want: 01/09/2009 How do I do this, I am new to PHP is it isnt obvous lol....

 

Thank you...

Link to comment
https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/
Share on other sites

Sure here is View Source, and no the date wont be the same it is from a hidden field that is contained within a loop so really what is being stored is the Date that item was saved to the db.

 

<form method="post" name="trackerfrm" action="">

        <input type="hidden" name="SysDate" value="01/09/2009" />        <input type="hidden" name="PlugDate" />

        <input type="hidden" name="vStart" />

        <input type="hidden" name="vCurTotal" />

        <input type="hidden" name="vPause" />

        <input type="hidden" name="vPauseDate" />

Erm, why are you passing it in a hidden field at all? The date is almost certainly going to be the same when the form is loaded as when it is submitted, right?

 

Did you see that question?

 

Why do you need to pass the sys date to it? Since it is the just date with no time/seconds it will be the same on page load...no need to pass it, just call the date function where you were grabbing the post data.

Sorry everyone, this is NOT the current date. It is coming from the db, it is the date that the record was added to the database. I understand the nameing is bad, but the root question is if you pass a date through the POST when you grab it on the other side how do you "retain" the exact data that was passed? In reality I am passing a String, it is just a hidden textbox

How are you echoing the data?

 

Ken

 

See that.

 

And if the date is stored in the database, why do you need to pass it to the form, using UPDATE syntax that date should never change...the reason we are asking is because it seems your logic is somewhat flawed and you are busting your head over something that is null and void.

 

Also are you using any JavaScript on that page?

Then you need to refer to Ken's question:

 

How are you echoing the data?

 

Ken

 

The string shouldn't change unless you do anything to it.

 

Incidentally, now would probably be a good time to point out that a user might modify that hidden field. Just because it's hidden, don't assume a malicious user wouldn't change it.

ok, here is an answer to Kens post. This is my PHP RAW code for the page that holds the hidden:

<?php

$CurDate = date("m/d/Y");

?>

 

<input type="hidden" name="SysDate" value="<?php echo $CurDate ?>" />

 

Submit Button....

 

Here is my page that is retrieving the data:

 

$pSysDate = $_POST["SysDate"];

echo $pSysDate

 

When I echo the value on the retrieving page it does this:

Friday, January 09, 2009 9:07:13 AM

 

If I am not understanding you post Ken let me know.

At the start of the script where you're echoing the field put:

<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
?>

 

and show us what appears.

 

There is no way that the statements you have shown us can do what you're showing.

 

Ken

Here is what I get:

 

Friday, January 09, 2009 10:09:59 AM

 

Array

(

    [sysDate] => 01/09/2009

    [PlugDate] => 00092009

    [vStart] => 10:09

    [vCurTotal] => 0

    [vPause] =>

    [vPauseDate] =>

    [vResume] =>

    [PlugDateResume] =>

    [vStop] =>

    [vStopDate] =>

    [vDStart] => Friday, January 09, 2009 10:09:59 AM

    [vDSuspend] =>

    [vDResume] =>

    [vDEnd] =>

    [vTrackerID] =>

    [vStatusSummary] =>

    [vFinalStatus] =>

    [Task] => asd

    [TaskType] => Maintenance

    [TaskRelation] => Production

    [siteList] => 529 Plans

    [RangeStartDates] => 1/8/2009

    [RangeEndDates] => 1/8/2009

)

 

 

Thats cool looks like a Dump of all my POST fields, thx... so I see the Proper Value, so why am I getting the full date when I echo

$_POST["SysDate"]? I dont understand.

oh crap. I think I found it. I am sorry, Shoot ME, Call me DUMB. But looking back and doing some undos it appears that I might have been confusing values, looks like I did an echo of a different var and Glazing over the code. Crap, works fine now.

 

I was wondering why if I pass 01/09/2009 via a textbox why PHP would convert it to a full date, I figured that PHP was seeing a DATE so it passed it to the date object or something....

 

Shoot, sorry how frustrating, wasted so much time DOH!  :o

oh crap. I think I found it. I am sorry, Shoot ME, Call me DUMB. But looking back and doing some undos it appears that I might have been confusing values, looks like I did an echo of a different var and Glazing over the code. Crap, works fine now.

 

I was wondering why if I pass 01/09/2009 via a textbox why PHP would convert it to a full date, I figured that PHP was seeing a DATE so it passed it to the date object or something....

 

Shoot, sorry how frustrating, wasted so much time DOH!  :o

 

Which is why, when you echo out a piece of code for debugging/testing you should put in an identifier before it such as:

echo "SysDate: " . $_POST['SysDate'];

 

What way you know what variable is being printed out and if the right one etc is printing.

 

However I would suggest you re-think putting the date in the form, and read the suggestions above and the warnings, such as data manipulation etc. Either way good luck!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.