We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31104
    • 108 Posts
    Hi, I’ve made a reservation widget that slides out from the left (with jquery) when you click on a tab, everything works great except for 1 detail:

    I have used validation on certain fields, so when the form is sent with an empty field it refreshes the page and hides my reservation form (which is hidden by default until you click on the tab again).

    Is it possible to send a user to a certain page with an "unsuccessful, please try again" message when the form is unsuccessful?

    Something like:
    &unsuccessfulRedirectTo=`123`
    



    Thanks smiley
      • 5340
      • 1,624 Posts
      You probably need to use hooks.

      Here’s an older tutorial on how you should do one: http://modxrules.com/articles/send-a-confirmation-email-with-formit
        • 31104
        • 108 Posts
        Hi cipa, thank you for pointing me in that direction, I was already looking into hooks and preHooks, and was pretty certain that was the way to go, the problem is that I just don’t have the faintest idea as to how I can access, or how I can tell if the form has not been sent.

        There’s no built-in hook to redirect upon unsuccessful sending, so I thought I’d take a look at formit.php (formit snippet) and I think I was pretty close to hardcoding the redirect by adding this:
        $url = $modx->makeUrl(123);
        $modx->sendRedirect($url);
        


        under the line 180 in this else statement:
        else {
            $modx->toPlaceholders($fi->validator->errors,$placeholderPrefix.'error');
            $errs = array();
            foreach ($fi->validator->errorsRaw as $field => $err) {
                $err = $field.': '.$err;
                $errs[] = str_replace('[[+error]]',$err,$validationErrorBulkTpl);
            }
            $errs = implode($validationErrorBulkSeparator,$errs);
            $validationErrorMessage = str_replace('[[+errors]]',$errs,$validationErrorMessage);
            $modx->setPlaceholder($placeholderPrefix.'validation_error',true);
            $modx->setPlaceholder($placeholderPrefix.'validation_error_message',$validationErrorMessage);
        
           /*  ---- > right here  */
        
        }
        

        But no cookie, so I kept going back to the drawing board a few times til I gave up and decided to just add a line before the send button where I state that if you don’t get a thank you page, the form hasn’t been sent.

        If anybody ever figures out how to make a preHook to redirect when the form fails, please share your findings.

        Thanks again.