Clear form values after sending the mail


i made a form like this and it works fine.

After sending the mail with the form values, I stay on the contact page and get a message, that the form has sent. But: My form contains still the sent values.

I want to clear the values, so the form is clear after sending and displaying the confirm-message.

Anybody have an idea :slight_smile:

In your form, use the value attribute, e.g.

<div class="field">
   <label for="name">Name <abbr title="required">*</abbr></label>
   <input type="text" id="name" name="name" value="<?= isset($data['name]? $data['name]: '' ; ?>>

In your controller:

// then after sending the mail, clear the $data array
$data = array();

// return the $data variable to template
return compact('alert', 'data');

Hi :slight_smile: thank you for the answer.
My problem is, that another person in my agency coded this files, but he left the agency.
I had this idea to clear the array(), too, but in the templates the values are given like this:

<label for="firstname"><?php echo l::get('i18nContactFirstname') ?> <span class="asterisk">*</span></label>
                                    <input type="text" id="firstname" name="firstname" <?php e($alert['firstname'], 'class="failed"') ?> value="<?php echo get('firstname'); ?>">

Do you have a solution for this? Maybe I edit the code and set the values in your way …

I don’t think this will work without changing the code.

Yep. Since the value that gets printed always comes from get(), there is no way to hide the content after the submission. Rewriting with a data array would make sense.

Okay, I will do this :slight_smile: Thank you texnixe and lukasbestle :slight_smile: