0
votes

I have created a website using cakePHP 3.I have created a mail form in the contact section using the form helper and the mail sender. The mail is working OK, but when I click the send (submit) button, it reloads the contact page and keep de input fields filled.

What I want is to not refresh the page, clear the form fields and show a modal. ¿Is this possible? ¿How can I do it?

I don't know if you guys need any code, so if you need it I will provide it.

Thanks.

1
I want is to not refresh the page - that means you submit the form with js. You should always put code in a question here. - AD7six

1 Answers

2
votes

If you want clear fields after submit form you can do in two way:

in view:

<?= $this->Form->input('email',['value' => '']); ?>

or in controller method after calling execute method unset your submited data like this:

$contact = new ContactForm();
if ($contact->execute($this->request->data)) {
   $this->request->data = [];

}

If sending success , you can set success flash message or other variable, and then in view display flash message or modal

$this->Flash->success(__('The Message has been sent.'));
// or
$this->set('modal', true);

in your view

<?php if(isset($modal) && $modal == true): ?>
   YOUR MODAL HERE
<?php endif; ?>