Jump to content

Recommended Posts

Posted

How do I check for errors (required fields not filled in, etc..)?

I need to redirect after a successful page save, but only if there are no errors.

public function init() {
    $this->pages->addHookAfter('save', $this, 'redirectMe');
}

public function redirectMe($event){
    if ($event->arguments(0) != "news") return;
    $this->session->redirect($this->config->url->admin . "/processwire/news/");
}

The code above redirects even if there are errors on the page.

Posted

I do think field errors are cleaned in the InputfieldWrapper render() methode.

So maybe you need an additional hook before InutfieldWrapper render and loop through the fields and count the errors.

  • Like 1
Posted

Thanks Martijn,

That got me thinking, maybe I can just check the notices?

$errors = false;
foreach(wire('notices') as $notice) {
    $notice instanceof NoticeError ? $errors = true : "";

}

Haven't tried that yet, just riffing.

Will report back.

  • Like 1
Posted

This seems to work. At least through some simple tests.

public function redirectMe($event){
    $page = $event->arguments(0);
    $errors = false;

    foreach(wire('notices') as $notice){
        if($notice instanceof NoticeError) $errors = true;
    }

    if (!$errors) $this->session->redirect($this->config->url->admin . "/processwire/news/");    
}
  • Like 1
Posted
 if you didn't delete the install.php for example does that prevent your $session->redirect?

Not sure, but in that case it's OK for it to fail, because the admin (me) has some cleanup to do. :)

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
  • Recently Browsing   0 members

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