Expression Engine SafeCracker Format Datepicker - php

Hi I am making a form in expression engine using safecracker and one of my fields called "date of birth" uses the date field type. The jQuery datapicker is being automatically added by expression engine but I can't see how to add any of the options or formatting I would normally add to datepicker when making a field of this type.
My normal code:
$(function() {
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
maxDate: new Date()
});
});
The only option I can think of is to make this field a text input and add the datepicker myself in the template but this would remove EE's date validation that it performs on this field type.
Is there anyway to add additional datepicker options to this field type?

Well, you can set datepicker="no" in your Safecracker tag, then add your javascript manually. However: you can't use your custom format as you show above - for the input to validate as a native EE date field, it must use the datePicker format yy-mm-dd, plus the current time in the format HH:MM AM/PM - which the datePicker doesn't do natively. (See this post by one of EE's developers for how they do this.)
An alternative would be to instead use the EEvent Helper date field, because it does not require the time portion to validate (though it too requires yy-mm-dd). However, datepicker="no"only affects native date fields, so you'd instead have to set safecracker_head="no" - but then you'll also lose any javascript or CSS required by other fieldtypes in your form.
Re: using a plain text field: in addition to the validation issue, your data would then be stored as whatever is input (mm/dd/yy), instead being converted a timestamp, which is far more useful and portable.
The only true solution is to write your own date fieldtype for this. Wouldn't be very difficult.

Related

How to add a time picker to grocery crud

I have two types of date time fields in my database. DATE and TIME. With the DATE field Grocerycrud gives you a date picker when adding a record. With the TIME field Grocerycrud only gives you a text field.
Is there any way to get Grocerycrud to show a time picker for TIME fields?
Use a datetime field instead and you'll get the datepicker and timepicker altogether.
If you wish to use only time fields you'll have to modify GC. This is not the correct way to extend GC but as development seems stopped I guess its ok.
Follow the instrucction from this post:
http://www.grocerycrud.com/forums/topic/1573-timepicker-implementation/#entry11462
After a long search and following through the above documentation which didn't work for me I devised my own solution. Convert the type of input field to time using jquery. It was sufficient for me although its not a robust method. It may help in certain situations at least
<script type="text/javascript">
$( document ).ready(function() {
var a = document.getElementById("field-ScheduledTime");
a.type="time";
});
</script>

Date Picker for selecting and viewing contents for that particular date

I need a date picker/selector written in php, jquery and probably mysql that is visible for the user to select a particular date and view the contents for that particular date.
An example can be found here
http://soccernet.espn.go.com/scores/_/league/eng.1/english-premier-league?cc=3888
Another example is http://www1.skysports.com/football/fixtures-results/06-september-2012.
You can use the JQuery UI Datepicker and modify it for your own purposes. There a lot of Date Pickers out there. In this case, Google will probably provide you with more answers than Stack Overflow :)

customizable date picker script for forms

I want to use date picker on my form for selecting date.
I googled for it and found mostly import library scripts from live site. I don't want to use them.They are of limited use and I can't customize them.
Is there any good customizable date picker plugin which I can integrate and customize according my needs
I am working on zend-framework and heared about zendx. Is there any inbuilt date picker which I can call on my form element and how ?
For one of my projects based on Zend Framework, I used the UI jQuery Datepicker. You can find it here: http://jqueryui.com/demos/datepicker/
Another usefull link is this: Zend Framework - JQuery - Date Picker - Format Date to YYYY-mm-dd
You can use Zendx library for make datepicker element. Read this one.
http://framework.zend.com/manual/en/zendx.jquery.view.html

How to pass value from datepicker to database?

by using form and post method in my program. It seems like my values of calendar are not able to insert into my database. I'm using jquery's datepicker and php to code. Please advice. Thanks
chances are your database is structured with a date format or datetime format. This is fine, but you will have to change the format of the date in the jquery UI after it is posted. Therefore if you have it as 12/19/2010 it would have to be changed to 2010-12-19 for the database to accept it. This is just a random guess since I don't know much more from your question.

free calendar with timestamp

I am working on form and I am looking for a free calendar/date/timestamp app that i can include in my form. basically, in the input text, i want users to click on the calendar icon and pick a date and a time stamp. that value should populate in the input text.
my next question is, in my mysql db, i am calling this field as "datetime", so i am hoping the values can be written in the db.
i am working with php and mysql.
thanks.
For the user interface you are describing to be added to the input field, jQuery Datepicker springs to mind.
http://jqueryui.com/demos/datepicker/
You'll need to include the jQuery library as well as the jQuery UI library. You can use the 'build your download' link and documentation on the jQuery library page to get a fully themed ui download to suit your design needs.
You'll need to make your form post to a server-side script that will take the field and insert it into the DB. Be careful - mysql date time is in the following format - YYYY-MM-DD HH:mm:SS. You can use strtotime and date to format the input from jQuery. After sanitizing the input, you could do something simple like:
date('Y/m/d H:i:s', strtotime($_POST['date']) )
You can use this to make sure in your server script that the date/time is in the proper format before it goes in the database.
This can be done with GUI
Take a look at jQuery UI Date-picker: http://jqueryui.com/demos/datepicker/
Regards to the date conversion there is plenty of functions to help you
http://www.php.net/manual/en/ref.datetime.php

Categories