Jump to content

How to do fromdatetime and todatetime validation


SIERRA
 Share

Recommended Posts

Hi,

  1. We have 'Seminar_Schedule' repeater field in the template (One of the Admin Control Panel Page)
  2. Inside the 'Seminar_Schedule' repeater field (parent), we have 'SS_Datetime' repeater field.
  3. Inside the 'SS_Datetime' repeater field (child), We have 'SS_Startdatetime' and 'SS_Enddatetime' fields.

How to do validation for 'SS_Startdatetime' and 'SS_Enddatetime' fields for below cases.

  1. 'SS_Startdatetime' should be lesser than to 'SS_Enddatetime'
  2. 'SS_Startdatetime' should not be equal to 'SS_Enddatetime'

PFA and Suggest,Screenshot_261.thumb.png.1f666e0249413a290a14d93bdf15cd47.png

Link to comment
Share on other sites

Hey @SIERRA could you please read the community rules, especially the section about "Rules for posting"?

You have posted several questions over the last years and often you just disappear. It might increase your chances to get helpful answers if you

  1. try to ask in a more polite and less demanding way and
  2. at least say thank you after someone replied and tried to help in his/her spare time for free.

Have a nice weekend and good luck with your project.

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi Sierra, that helped once me solve a similar problem ..

$this->addHookAfter('InputfieldDatetime::processInput', function(HookEvent $event) {
    // Get the object the event occurred on, if needed
    $InputfieldDatetime = $event->object;

    // An 'after' hook can retrieve and/or modify the return value
    $return = $event->return;

    $post = $this->wire('input')->post;
    // change date string to timestamp
    $firstdate = strtotime($post->date_start);
    $lastdate = strtotime($post->date_end);

    // if first date greater than or equal to last date
    if ($firstdate > $lastdate && $lastdate != '' ) {
        $field = $event->object;
        if ($field->name == 'date_start' || $field->name == 'date_end') {
            // get the page being edited
            $page = $this->wire('modules')->ProcessPageEdit->getPage();
            // ensure we don't save 'erroneous' dates; we revert to older saved (db) dates or blank
            $oldDate = $page->get($field->name);
            $field->value = $oldDate;
            // only show error on first date field
            if ($field->name == 'date_start') $field->error("");
            if ($field->name == 'date_end') $field->error("") . $field->message("Das Datum zum $field->label muss in der Zukunft liegen, bitte die Angabe zum Veranstaltungsbeginn beachten!");
        }
    }

    // Populate back return value, if you have modified it
    $event->return = $return;
});

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...