jbmoyer Posted January 9, 2009 Share Posted January 9, 2009 ... 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... Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/ Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 can you do a view source after loading the page and show what the hidden field looks like? Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733353 Share on other sites More sharing options...
GingerRobot Posted January 9, 2009 Share Posted January 9, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733354 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 @GingerRobot lol, very true, why didn't I think of that? Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733355 Share on other sites More sharing options...
jbmoyer Posted January 9, 2009 Author Share Posted January 9, 2009 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" /> Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733364 Share on other sites More sharing options...
kenrbnsn Posted January 9, 2009 Share Posted January 9, 2009 How are you echoing the data? Ken Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733365 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733366 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 Like Ginger Robot said, the chance of the date changing between someone filling in the form and submitting it is tiny it would have to be midnight, lol Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733367 Share on other sites More sharing options...
jbmoyer Posted January 9, 2009 Author Share Posted January 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733375 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733380 Share on other sites More sharing options...
GingerRobot Posted January 9, 2009 Share Posted January 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733381 Share on other sites More sharing options...
jbmoyer Posted January 9, 2009 Author Share Posted January 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733384 Share on other sites More sharing options...
kenrbnsn Posted January 9, 2009 Share Posted January 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733388 Share on other sites More sharing options...
jbmoyer Posted January 9, 2009 Author Share Posted January 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733394 Share on other sites More sharing options...
jbmoyer Posted January 9, 2009 Author Share Posted January 9, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733400 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 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! 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! Quote Link to comment https://forums.phpfreaks.com/topic/140153-passing-a-date-via-a-hidden-form-field/#findComment-733414 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.