How to remove form after it's submitted in Laravel PHP?

- 1 answer


My site uses OctoberCMS and I have a contact form in which I want to display a success message in a partial and hide the form after it's submitted. Here is the code snippet for the form,I cleared unnecessary parts of it :

<form role="form" class="cntct" id="cntct" data-request="onSend" data-request-update="success: '#result'">
     <div class="form-group">
      <!-- Some input fields here !--> 
         <div class="row">
            <div class="col-sm-6">
               <button type="submit" class="btn btn-lg btn-info">Send message</button>
 <div id="result">
   {% partial 'success' %}

Form is working, I can send emails and the success partial shows its content without any errors. I just want to remove the form,if it's possible by using PHP, and display only #result container.




If you put the form partial inside a div with an id="form" like this:

<div id="form">
    {% partial __SELF__~"::partials/form" %}

then you can hide the the form and show the result from the ajax handler by returning the new partial to be rendered in the div:

public function onSend()
    # save the data

    return ['#form' => $this-renderPartial('@partials/success')];

This assumes you have the form and success partial in your components partials folder.