How to remove form after it's submitted in Laravel PHP?
Ad
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>
</div>
</div>
</form>
<div id="result">
{% partial 'success' %}
</div>
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.
Ad
Answer
Ad
If you put the form partial inside a div with an id="form"
like this:
<div id="form">
{% partial __SELF__~"::partials/form" %}
</div>
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.
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad