I’m creating easy itemizing web site, and within the itemizing publish i’ve single web page the place i displayed a few of information and Further i’ve added {custom} kind. The shape is submitted efficiently however when i attempt to ship e mail to admin i obtained e mail physique that i designed. However what i need? I solely need to present the shape is submitted efficiently! Bellow my full code:
Right here is the screenshoot: https://prnt.sc/HfSo3I_o1K1a
<div class="for_tilbud">
<kind id="form_tilbud" motion="<?php echo admin_url('admin-ajax.php'); ?>" methodology="publish">
<label>Fullt navn *
<enter sort="textual content" identify="identify" class="custom-form submit-field"></label>
<label class="mt-25">Din e-post *
<enter sort="textual content" identify="e mail" class="custom-form submit-field"></label>
<label class="mt-25">Tlf.nummer *
<enter sort="textual content" identify="quantity" class="custom-form submit-field"></label>
<label class="mt-25">Få tilbud om *
<choose class="form-control submit-field choose submit-field" identify="getoffer" id="getoffer">
<possibility worth="0" disabled="" chosen="">Velg produkt</possibility>
<possibility worth="trafikalt-grunnkurs">Trafikalt grunnkurs</possibility>
<possibility worth="kjoretime">Kjøretime</possibility>
<possibility worth="sikkerhetskurs-vei">Sikkerhetskurs på vei</possibility>
<possibility worth="sikkerhetskurs-bane">Sikkerhetskurs på bane</possibility>
<possibility worth="veiledningstime">Veiledningstime</possibility>
<possibility worth="praktisk-prove">Praktisk prøve (oppkjøring)</possibility>
<possibility worth="annet">Annet</possibility>
</choose>
</label>
<enter sort="hidden" identify="motion" id="form_tilbud_submit_action" worth="form_tilbud_submit_action">
<enter sort="submit" identify="Submit" id="form_tilbud_submit" class="btn color2-bg mt-25">
<div class="reSult"></div>
</kind>
</div>
<script>
jQuery('#form_tilbud').on('submit', perform(e) {
e.preventDefault();
var jQueryform = jQuery(this);
jQuery.ajax({
sort: "POST",
url: jQuery(this).attr('motion'),
dataType: 'json',
cache : false,
information: jQuery("#form_tilbud").serialize(),
beforeSend: perform() {
// setting a timeout
jQuery('#form_tilbud_submit').attr('disabled', 'disabled');
jQuery('#form_tilbud_submit').val('Sending Request');
},
success: perform (outcome) {
console.log(outcome);
},
error: perform (xhr, standing, error) {
jQuery('#form_tilbud_submit').removeAttr('disabled');
jQuery('#form_tilbud_submit').val('Submit');
jQuery('.reSult').html(xhr.responseText);
jQuery(':enter','#form_tilbud')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('chosen');
}
});
});
</script>
My {custom} mail formatting and performance:
<?php
// Motion perform
perform form_tilbud_submit_action() {
$identify = sanitize_text_field($_POST['name']);
$e mail = sanitize_email($_POST['email']);
$quantity = sanitize_text_field($_POST['number']);
$getoffer = sanitize_text_field($_POST['getoffer']);
$post_id = sanitize_text_field($_POST['post_id']);
$schoolName = get_the_title($post_id);
$errors = [];
if (trim($_POST['name']) == '') {
$errors['name'] = 'navnefelt er obligatorisk';
}
if (trim($_POST['email']) == '') {
$errors['email'] = 'e-postfelt er obligatorisk';
}
if (trim($_POST['number']) == '') {
$errors['phone'] = 'telefonfelt er obligatorisk';
}
if (trim($_POST['getoffer']) == '') {
$errors['getoffer'] = 'beskrivelsesfeltet er obligatorisk';
}
foreach ($errors as $error) {
echo '<div class="FormErrors">' . json_encode($error) . '</div>';
die();
}
if(empty($errors)) {
// Ship to admin
$to = get_bloginfo('admin_email');
$topic="En ny elev ønsker tilbud";
$physique = my_email_body_function($identify,$e mail,$quantity,$getoffer, $schoolName);
$headers = array('Content material-Sort: textual content/html; charset=UTF-8');
wp_mail( $to, $topic, $physique, $headers );
echo '<div class="FormSuccess">' . json_encode("Request Ship Efficiently!") . '</div>';
die();
}
}
// Vital motion hooks
// Use our particular motion form_tilbud_submit_action to course of the info associated to our request
add_action( 'wp_ajax_form_tilbud_submit_action', 'form_tilbud_submit_action' );
add_action( 'wp_ajax_nopriv_form_tilbud_submit_action', 'form_tilbud_submit_action' );
// E mail physique perform declaration
perform my_email_body_function($identify,$e mail,$quantity,$getoffer,$schoolName) {
ob_start(); // We have now to activate output buffering. VERY IMPORTANT! or else wp_mail() wont work
// Then setup your e mail physique utilizing the postfields from the attritbutes handed on. ?>
<desk function="presentation" model="width:100%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;">
<tr>
<td align="middle" model="padding:0;">
<desk function="presentation" model="width:602px;border-collapse:collapse;border:1px strong #cccccc;border-spacing:0;text-align:left;">
<tr>
<td align="middle" model="padding:40px 0 30px 0;background:#2F5888;">
<img src="http://combrokers.co/college/belongings/klasseb-white.png" alt="" width="200" model="peak:auto;show:block;" />
</td>
</tr>
<tr>
<td model="padding:36px 30px 42px 30px;">
<desk function="presentation" model="width:100%;border-collapse:collapse;border:0;border-spacing:0; text-center">
<tr>
<td model="padding:0 0 36px 0;colour:#153643; text-center">
<h1 model="font-size:24px;margin:0 0 20px 0;font-family:Arial,sans-serif;">Hei <?php echo $identify; ?></h1>
<p model="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">Din forespørsel er nå sendt til <?php echo $schoolName; ?>, Du vil bli kontaktet så snart som mulig.
</p>
</td>
</tr>
<tr>
<td model="padding:0;">
<desk function="presentation" model="width:100%;border-collapse:collapse;border:0;border-spacing:0;">
<tr>
<td> Navn </td>
<td>:</td>
<td><?php echo $identify; ?></td>
</tr>
<tr>
<td> Epost </td>
<td>:</td>
<td><?php echo $e mail; ?></td>
</tr>
<tr>
<td> Telefonnummer </td>
<td>:</td>
<td><?php echo $quantity; ?></td>
</tr>
<tr>
<td> Få tilbud om </td>
<td>:</td>
<td><?php echo $getoffer; ?></td>
</tr>
<tr>
<td> Navn på kjøreskolen </td>
<td>:</td>
<td><?php echo $schoolName; ?></td>
</tr>
</desk>
</td>
</tr>
</desk>
</td>
</tr>
<tr>
<td model="padding:30px;background:#2F5888;">
<desk function="presentation" model="width:100%;border-collapse:collapse;border:0;border-spacing:0;font-size:9px;font-family:Arial,sans-serif;">
<tr>
<td model="padding:0;width:50%;" align="left">
<p model="margin:0;font-size:14px;line-height:16px;font-family:Arial,sans-serif;colour:#ffffff;">
© All rights reserved
</p>
</td>
<td model="padding:0;width:50%;" align="proper">
<desk function="presentation" model="border-collapse:collapse;border:0;border-spacing:0;">
<tr>
<td model="padding:0 0 0 10px;width:38px;">
<a href="https://www.fb.com/klasseb.no" model="colour:#ffffff;"><img src="https://belongings.codepen.io/210284/fb_1.png" alt="Fb" width="38" model="peak:auto;show:block;border:0;" /></a>
</td>
</tr>
</desk>
</td>
</tr>
</desk>
</td>
</tr>
</desk>
</td>
</tr>
</desk>
<?php
return ob_get_contents();
ob_get_clean();
}