close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

datepicker field storing all dates to database as 1/1/70 no matter what user selects?

Thread began 1/28/2020 3:16 am by Nathon Jones Web Design | Last modified 8/12/2020 6:19 pm by Ray Borduin | 1627 views | 14 replies |

Nathon Jones Web Design

datepicker field storing all dates to database as 1970-01-01 no matter what user selects?

Can anyone help me decipher why my datepicker field is storing all dates to database as 1970-01-01?

Here's the field....

<input type="text" class="form-control" name="DOB" id="DOB" placeholder="Date of Birth" maxlength="10" value="<?php echo(isset($_GET['v1'])?ValidatedField("healthscreeningform_984","DOB"):$rsEDITFORM->getColumnVal("SMCformDOB")?date("d/m/Y",strtotime($rsEDITFORM->getColumnVal("SMCformDOB"))):"") ?>" required>



Here's the datepicker JS...

<script type="text/javascript">
$(function() {
$( "#DOB" ).datepicker({
dateFormat : 'yy-mm-dd',
changeMonth : true,
changeYear : true,
yearRange: '-100y:c+nn',
maxDate: '-1d'
});
</script>



There are effectively three states this form field can be in....
1) Blank - yet to be filled in by the user
2) Validated value - user has submitted the form, but validation has failed somewhere
3) Recordset value - user is editing the form

The recordset value is converted so that it's displayed in UK format.

Could any of the above be causing this issue?
Hope you can help. Thank you.
NJ

Sign in to reply to this post

Nathon Jones Web Design

WA Server Validation is defaulting the Date of Birth datepicker field to 1970-01-01 when validation fails on any field..

How do we fix this? Link to the form is provided below. If you enter a number in the Name field, validation will fail (so you can check this).

Thank you.
NJ

Sign in to reply to this post

Ray BorduinWebAssist

Please attach the page. I'm away from the office for two weeks so I don't have the ftp connections on my laptop I would normally be able to access.

Sign in to reply to this post
Did this help? Tips are appreciated...

Nathon Jones Web Design

I've had to create a hacked solution for this, as the client was at the end of their tether. WA Server Validations definitely does cause the datepicker plugin to revert to 01-01-1970 though, if validation fails.

I created a test page, to make sure I wasn't going mad if nothing else, and the results were the same. I attach that page and if you enter a number in the name field, validation will fail. The date selected will be wiped and replaced with 01-01-1970.

Giving this some serious thought, the problems I'm having will likely be because I need this field to have three separate states. It might be helpful if I explained those in more detail....

1) Blank - when a new user accesses the form then the datepicker field - for date of birth - needs to be blank, ready for the user to select their dob.

2) Validated value - when the form is submitted, and validation fails, the datepicker fields needs to retain the value that the user has entered. As things stand, this is where the value is wiped and replaced with 01-01-1970.

3) Recordset value - once the user has submitted the form, the details are saved to database. The form switches to being an UPDATE behaviour. The datepicker field, therefore, needs to display the date value from recordset.

This ended up being my hack/hatchet job at getting this to work...

<div class="form-group row">
<label for="DOB" class="col-sm-4 col-form-label">Date of Birth</label>
<div class="col-sm-4">

<div class="input-group">
<?php if ($rsEDITFORM->TotalRows == 0) { ?><!-- if new user -->
<input type="text" class="form-control" name="DOB" id="datepicker_1" placeholder="Date of Birth" maxlength="10" value="<?php echo((ValidatedField("healthscreeningform_984","DOB")?ValidatedField("healthscreeningform_984","DOB"):date("d-m-Y"))); ?>" aria-describedby="basic-addon2" required>
<div class="input-group-append" style="cursor: pointer;" onclick="$('#datepicker_1').focus();"><span class="input-group-text" id="basic-addon2"><i class="far fa-calendar"></i></span></div>
<?php } else { ?><!-- if form has been submitted -->
<input type="text" class="form-control" name="DOB" id="datepicker_1" placeholder="Date of Birth" maxlength="10" value="<?php echo($rsEDITFORM->getColumnVal("SMCformDOB")?date("d-m-y",strtotime($rsEDITFORM->getColumnVal("SMCformDOB"))):""); ?>" aria-describedby="basic-addon2" required>
<div class="input-group-append" style="cursor: pointer;" onclick="$('#datepicker_1').focus();"><span class="input-group-text" id="basic-addon2"><i class="far fa-calendar"></i></span></div>
<?php } ?>
</div><!-- /input group -->

</div><!-- /col-sm-4 -->
</div><!-- /form-group row -->



Let me know if you need the database connection script referenced in this page.

I'm also having some issues with duplicate orders on this site - Add to Cart isn't overwriting a product that already exists in the basket, but I'll detail that in a seperate forum post.

Would appreciate your advice on the above.
Thank you.
NJ

Sign in to reply to this post

Ray BorduinWebAssist

I'll need FTP access and a URL to reproduce the issue in order to debug this. The code looks correct to me.

Sign in to reply to this post
Did this help? Tips are appreciated...

Nathon Jones Web Design

Hi Ray,

I was sure we had this one resolved but I've spotted another occurence of this problem on this site, where the date defaults back to 01-01-70.

If you sign into the site with the user information provided below and select order ref 3835, you will see six tabs across the top:
Certificate / Step 1 / Step 2 / Step 3 / Step 4 / Step 5

Each of the "Step" tabs has an "Edit & Save" button at the bottom.
If you go to Tab 1 and click "Edit & Save", it reverts the date back to 01-01-70, however this doesn't happen if you select the "Edit & Save" button on any of the other Step tabs.

Can you see why this is? FTP details provided below also.
Thank you.
NJ

EDIT:
On an update form, should the defaultDate be null in the datepicker script, considering that value should be being populated from database?
Could this be the cause of the 01-01-70 issue?

EDIT 2:
Commented out the defaultDate: null line in the script and now it's saving the date as 04-08-01!?

Sign in to reply to this post

Nathon Jones Web Design

Just sent a donation over via PayPal Ray. Hoping that you can help me resolve this particular issue.
My apologies again for not calling back the other evening. A situation developed and I could not get back to the office that evening.
Appreciate your help, as ever.
Thank you.
NJ

Sign in to reply to this post

Ray BorduinWebAssist

The problem is that you are submitting the date with the format: m-d-y

So it might look like: 04-08-05

Well php doesn't know which one of those is the year and which one is the day. It assumes you are using standard database format of y-m-d and it switches the month and the year each time you update.

The solution is to make sure to use a 4 digit date so it can't get confused. I updated the datepicker on the page to use a 4 digit date and that seems to have fixed the problem.

Sign in to reply to this post
Did this help? Tips are appreciated...

Nathon Jones Web Design

Thank you Ray.

Did you just change "d-m-y" to "d-m-Y", or did you change the script too?
NJ

Sign in to reply to this post

Nathon Jones Web Design

The datepicker isn't working now Ray. If you attempt to change the date, it enters a very strange format into the field - dd-mm-yyyyyyyy?

Line 1813 in view_order.php is this:

<input type="text" class="form-control" name="DOB" id="datepicker_1" placeholder="Date of Birth" maxlength="10" value="<?php echo($rsEDITFORM->getColumnVal("SMCformDOB")?date("d-m-Y",strtotime($rsEDITFORM->getColumnVal("SMCformDOB"))):""); ?>" aria-describedby="basic-addon2" required<?php if($_SESSION['SMCinACCESSID'] > 1 && ($rsEDITFORM->getColumnVal("SMCorderSTATUSID") != "" && $rsEDITFORM->getColumnVal("SMCorderSTATUSID") < 4)) { ?> disabled<?php } ?>>



This form has validation running on it so my default value should actually be this, right?

<?php echo(isset($_GET['v1'])?ValidatedField("vieworder_201","SMCformDOB"):$rsEDITFORM->getColumnVal("SMCformDOB")?date("d-m-Y",strtotime($rsEDITFORM->getColumnVal("SMCformDOB"))):""); ?>



This DOB field, and data, has been very problematic on this project.
Hope you can help resolve it.
Thank you.
NJ

EDIT: Testing offline, I've changed the DOB field to:

<input type="text" class="form-control" name="DOB" id="datepicker_1" placeholder="Date of Birth" maxlength="10" value="<?php echo(isset($_GET['v1'])?ValidatedField("vieworder_201","SMCformDOB"):$rsEDITFORM->getColumnVal("SMCformDOB")?date("d-m-Y",strtotime($rsEDITFORM->getColumnVal("SMCformDOB"))):""); ?>" aria-describedby="basic-addon2" required<?php if($_SESSION['SMCinACCESSID'] > 1 && ($rsEDITFORM->getColumnVal("SMCorderSTATUSID") != "" && $rsEDITFORM->getColumnVal("SMCorderSTATUSID") < 4)) { ?> disabled<?php } ?>>


...but it has made no difference. :(

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...