Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
3 - 0 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
     

Re: XoopsFormDateTime empty field?
by Mamba on 2013/8/24 22:46:06

Yes, that was a very good solution!

And it shows how searching on the XOOPS Website can help people to avoid reinvent ing the wheel!

A client of mine wanted to have a Calendar field that would show as a default "YYYY/MM/DD", and to only change after the user clicks on the "calendar button". If not, it would save to the database the default value "YYYY/MM/DD".

I was curious if somebody was faced with similar issue, and I've found your post, and with a small modification, it was perfect!

So thank you for sharing! It was helpful and it saved me some time!

And it demonstrates nicely the power of OOP!


Re: XoopsFormDateTime empty field?
by bumciach on 2012/1/19 12:11:41

Better solution - use OOP: extend original class XoopsFormTextDateSelect and add parameter $autofill

le="color: #000000"><?php class pfFormTextDateSelect extends XoopsFormTextDateSelect { /** * Constructor * * @param string $caption Caption * @param string $name "name" attribute * @param int $size Size * @param int,string $value Initial date (timestamp format) or English textual datetime description which can be converted to timestamp (see: strtotime PHP function) * @param bool $autofill If $value is empty or not recognized textual datetime the form field filled current date ($autofill = true) or leave empty */ function pfFormTextDateSelect($caption, $name, $size = 15, $value = 0, $autofill = true) { // previous to PHP 5.1.0 you would compare with -1, instead of false if ( strtotime($value) !== false OR strtotime($value) != -1 ) { $value = strtotime($value); } if ( $autofill === true ) { $value = !is_numeric($value) ? time() : intval($value); $value = ($value == 0) ? time() : $value; } else { $value = !is_numeric($value) ? '' : intval($value); $value = ($value == 0) ? '' : $value; } $this->XoopsFormText($caption, $name, $size, 25, $value); } }


Moreover this class accepts English textual datetime description and convert it into a timestamp (see http://php.net/manual/en/function.strtotime.php).
Example, this displays a later date by one day:
le="color: #000000"><?php new pfFormTextDateSelect('', 'test', 10, '+1 day', false);

Empty field:
le="color: #000000"><?php new pfFormTextDateSelect('', 'test', 10, '', false);


Re: XoopsFormDateTime empty field?
by bumciach on 2012/1/18 10:59:05

NOTICE: This my function from above doesn't work since Xoops 2.5.4. There were changes in xoops calendar and the file: /include/calendarjs.php even not exist in the latest Xoops.
Re: XoopsFormDateTime empty field?
by bumciach on 2010/1/7 11:35:40

To do this I have made this function.
le="color: #000000"><?php function pf_dateForm($c, $n, $s, $v, $alt='calendar') { global $xoopsModule; $jstime = formatTimestamp( strtotime(date('Y-m-d')), 'F j Y, H:i:s' ); include_once XOOPS_ROOT_PATH . '/include/calendarjs.php'; $tray = new XoopsFormElementTray($c,''); $frm = new XoopsFormText('', $n, $s, 10, $v); $tray->addElement($frm); $img="<img alt='" . $alt . "' src='" . XOOPS_URL . "/modules/" . $xoopsModule->getVar('dirname') . "/images/date.png' style='cursor: pointer;' onclick='return showCalendar("" . $n . "");' />"; $btn = new XoopsFormLabel('',$img); $tray->addElement($btn); return $tray; }

and then into script:
le="color: #000000"><?php $form -> addElement( pf_dateForm(...) );


However, I needed only date form without time, but I think it would be easy to add.
In my solution I replace the standard button [...] by image located in '/modules/mymodule/images/date.png'.
XoopsFormDateTime empty field?
by frankblack on 2010/1/4 18:12:48

When I use XoopsFormDateTime the script always enters a value into the text field, which is very nice, but not always wanted.

I just want to have an empty input field, so that the current date/time will be not inserted when not set on purpose.

Who's Online

116 user(s) are online (52 user(s) are browsing Support Forums)


Members: 0


Guests: 116


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits