Hi,
I have this code to send a summary.
<?php
return function($site, $pages, $page) {
$form = uniform(
'contact-form',
array(
'required' => array(
'first-name' => '',
'last-name' => '',
'message' => '',
'_from' => 'email'
),
'actions' => array(
array(
'_action' => 'email',
'to' => $site->to()->html(),
'sender' => get('_from'),
'subject' => 'Contact website',
'service' => 'phpmailer',
'snippet' => 'uniform'
),
array(
'_action' => 'email',
'to' => get('_from'),
'sender' => $site->to()->html(),
'subject' => 'Thank you for contacting me, {first-name} {last-name}!',
'service' => 'phpmailer',
'snippet' => 'uniform-thanks'
)
)
)
);
return compact('form');
};
My problem here is that when I send the message, the fields don’t be cleared. The values i entered are still there.
I use this uniform https://blog.the-inspired-ones.de/ajax-uniform. If I remove the second aray it works again.
Here is my code.
<form id="form" method="post">
<input type="text" name="first-name" id="firstname" placeholder="First Name" />
<input type="text" name="last-name" id="lastname" placeholder="Last Name" />
<input type="email" name="_from" id="email" placeholder="Mail" />
<textarea name="message" id="message" placeholder="Message"></textarea>
<label class="form__potty" for="website" style="display: none;">Please leave this field blank</label>
<input type="text" name="website" id="website" class="form__potty" style="display: none;" />
<input type="hidden" name="_submit" value="<?php echo uniform('contact-form')->token() ?>">
<span id="feedback"></span>
<button id="form-submit" type="submit">Send Message</button>
</form>
<script>
window.onload = function () {
$('#form-submit').click(function (e) {
e.preventDefault();
$.post(
'<?php echo $page->children()->find('send')->url()?>',
$('#form').serialize()
)
.then(function (response) {
var feedback = $('#feedback');
feedback.removeClass('success error').text(response.message);
$('input, textarea').removeClass('erroneous');
if (response.success) {
feedback.addClass('success');
$('input, textarea').prop('value', '');
$('#form-submit').prop('disabled', 'disabled');
} else {
feedback.addClass('error');
for (var i = response.errors.length - 1; i >= 0; i--) {
$('[name="' + response.errors[i] + '"]').addClass('erroneous');
};
}
});
});
};
</script>
What is the solution here?
Thanks for helping.