Use of Date Picker inside a form
2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 21, 2022 (RSS)
Hi
I have created a form to insert data in a section using the Form Generator plugin. I want to use a date picker instead of the default three boxes for month/date/year for a date field in the form. I have used the instructions I found in the forum (https://www.interactivetools.com/forum/forum-posts.php?postNum=2230132#post2230132), and the date picker correctly appears in the form. However, the value chosen does not appear in the corresponding section field when the form is submitted.
You can see the code used underneath. The name of the date field is "examination date".
<input id="datePicker" type='text' name='examination_date' value='' />
<script type='text/javascript'>
$(function() {
if ($.datepicker != undefined) {
$('#datePicker').datepicker({
showOn: 'button',
buttonImage: '/logbook/3rdParty/jqueryUI/calendar.gif',
buttonImageOnly: true,
dateFormat: 'yy-mm-dd 00:00:00'
});
}
});
</script>
Is there anything I could do?
Regards,
Andreas Lazaris
By daniel - September 21, 2022
Hey Andreas,
If you've created the form with Form Generator, you will probably have a section of code like this in the generated script:
if (fg_util_isPartialDate('examination_date')) { $_REQUEST['examination_date'] = ''; } // clear invalid dates
else { $_REQUEST['examination_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", @$_REQUEST['examination_date:year'], @$_REQUEST['examination_date:mon'], @$_REQUEST['examination_date:day'], 0, 00, 00); }
These lines are part of the date validation when a date field is being handled by the three dropdowns. Changing to a single input can cause some unexpected behaviour. Try commenting these lines, and let me know if that helps.
Thanks!
Technical Lead
interactivetools.com