Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

reactjs - InertiaJS Form Responses opening in Modal, with a quick Cache-Control Message

Been struggling with this one for the better part of a day, and I'm not finding much about it.

This is just a simple form component with some Laravel validation, and it just makes an API request and returns an error or success via a flash message. This is all documented in a fairly straightforward manner.

However, on either error or success, Inertia returns the Redirect in a modal, every time.

Code is below:

Form Component (React)

    function handleSubmit(e) {
        e.preventDefault()
        setSending(true)
        Inertia.post('/shop/quote-request', formValues, {
            onFinish: setSending(false),
        })
    }

Controller

    public function standardSubmit(Request $request): string
    {
        $form = $this->validate($request, [
            'companyName' => 'required|max:50',
            'name' => 'required|max:50',
            'email' => 'required|email:rfc,dns',
            'phoneNumber' => 'required'
        ]);
        if (empty($request['comments'])) {
            $comments = 'No Content';
        } else ($comments = $request['comments']);
        try {
            Zendesk::tickets()->create([
            'subject' => 'Subject',
            'recipient' => '[email protected]',
            'email_cc_ids' => '',
            'tags' => 'mtsps-tag',
            'requester' => [
                'email' => $form['email'],
                 'name' => $form['name']
            ],
            'comment' => [
                'html_body' =>
                "Company Size: " . $request['size']
                . "</br></br>" . "Message: " . $comments

            ],
            'group_id' => 'xxxxxxxxx',

            'priority' => 'normal'
        ]);
        } catch (Throwable $th) {
            return Redirect::route('shop.quote_request')->with('error', 'Something went wrong, please try again.');

        }
        return Redirect::route('shop.quote_request')->with('success', 'Your message has been delivered, someone will be in touch soon.');
    }

And the part I really don't understand: the text that renders in the modal before the component re-renders. enter image description here

Really appreciate any help here, happy to answer any questions or give any further detail on this if I've left anything out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm pretty sure it's the return type of your controller method. It's set to string instead of IlluminateHttpRedirectResponse - should work after you remove/replace it. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...