MyBB Hacks

Full Version: How to add a new Input Field Type?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
If you want d-m-Y date format in newthread and editpost, you need to set the format into my_date('d-m-Y',{VALUE}) in your input text and use dd-mm-yyyy in your Javascript (see my example before), then use the Custom regex (the new Custom regex uses - as separators, not /).
Thank youuuuu Rate Biggrin Biggrin Biggrin Now works perfectly!

So the code is:

Text Mask Filter (regex): ^(0?[1-9]|[12]\d|3[01])\-(0?[1-9]|1[012])\-((?:19|20)\d\d)$

Input Formatter: <?=strtotime({VALUE})?>

Input Field HTML:

Code:
<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="<if {VALUE} && !$mybb->input['my_post_key'] then><?=my_date('d-m-Y',{VALUE})?><else>{VALUE}</if>" id="datepicker" />


Display Format: <?=date('d-m-Y', {VALUE})?>

Now when I edit or create a new thread I haven't more problems with format date and if I don't add a date isn't a problem. And no problem with 1970 Biggrin

Thank you again Biggrin

Glad you can solve it. Nice usage of custom field Smile
is there a JS to add a time to the date? thanks

Quote:I use this to move threads on date of expiration

AND do you do it automatically with a task or manually

ALSO
what regex would i need for

Code:
16/09/2015 00:00


and date and time format?

my_date('d-m-Y H:i',{VALUE})

EDIT: I am having trouble with timezone i guess, 7hrs behind, but why? I add the date and then edit the post and its 7 hrs behind....

how can i correct this?

(09-25-2015 01:51 PM)ollie2015 Wrote: [ -> ]is there a JS to add a time to the date? thanks

Javascript Code
new Date(new Date('2000-01-01 12:00:22') + 3600*1000).toString()


(09-25-2015 01:51 PM)ollie2015 Wrote: [ -> ]ALSO
what regex would i need for

Code:
16/09/2015 00:00

Code:
^\d\d/\d\d/\d\d\d\d \d\d\:\d\d$

May vary depending on what validation you want and pattern capturing.

(09-25-2015 01:51 PM)ollie2015 Wrote: [ -> ]my_date('d-m-Y H:i',{VALUE})

EDIT: I am having trouble with timezone i guess, 7hrs behind, but why? I add the date and then edit the post and its 7 hrs behind....

how can i correct this?
If you're applying the timezone correction twice, then times are going to be off.  Don't use my_date if you intend to use it later, because it will correct timezone (use date instead).
Hi,

I still have a problem with this, same topic.

If I already have an existing thread, and I edit the Original Post, the "date" field (which has the datepicker) shows up as the unix time integer.

If I then click on that textbox, and pick a date, it shows up in the right dd-mm-yy format. How do I make it show in the right format as soon as editpost.php loads?

Cheers!
Edit: scratch that. I got confused how to combine the code in the above posts.

Fixed it as follows:

Used this Input Field HTML:

Code:
<if THIS_SCRIPT == 'editpost.php' && !isset($mybb->input['processed']) then>

<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="<?=date('d-m-Y', (int){VALUE})?>" id="datepicker" style="position: relative; z-index: 10000;" />

<else>

<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="{VALUE}" id="datepicker" style="position: relative; z-index: 10000;" />

</if>

Update: It isn't enough just to check if the script is 'editpost.php'.

If the user clicks preview, or makes an error on attempting to submit the edit, editpost.php passes the text value of the textbox to the next page. This text value then gets put through the date() function, leading to the 1970 date problem.

The solution is to check if the 'processed' flag is set:

Code:
<if THIS_SCRIPT == 'editpost.php' && !isset($mybb->input['processed']) then>


Updated the previous post's code.

Pages: 1 2 3
Reference URL's