Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3800

if empty => take today's date

$
0
0

i would need an if else issue.

my code works as long the user inputs an date for 'post_dup', otherwise stops with the alert: "An SQL error occurred: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'post_dup' cannot be null"

in this case editor should take today's date. can anyone help me out with the correct syntax within my existing code.
thx a lot

// Vars
$date_sql = 'Y-m-d H:i:s';  // 2019-12-31 23:59:00  siehe php.net/manual/de/function.date
$datedate = 'd/m/Y';        // 31/12/2019           editor field => format:'DD/MM/YYYY'
$datetime = 'd/m/Y - H:i';  // 31/12/2019 - 12:12   editor field => format:'DD/MM/YYYY - HH:mm'

use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

$db->sql('set names utf8');
$editor = Editor::inst(
  $db, 'alle_post', 
       'alle_post.post_idn' /* Primary Key */
  )
    ->fields(
    Field::inst('alle_post.post_dup')
      ->validator(Validate::dateFormat($datetime))
      ->getFormatter(Format::datetime( $date_sql, $datetime))
      ->setFormatter(Format::datetime( $datetime, $date_sql)),
    );

$editor
  ->debug(true)
    ->process($_POST)
    ->json();

Viewing all articles
Browse latest Browse all 3800

Trending Articles