Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

Create acf_form save data and Send mail from Frontend

Create acf_form save data and Send mail from Frontend

This post will cover how to create a form on the front end of your website using Advanced Custom Field acf_form() function. We can store data as well as send email also.

To load necessary CSS, JavaScript and other stuff we need to call acf_form_head() first then using acf_form() we can display and save data and using action add_action(‘acf/save_post’, ‘my_save_post’); can send email also. code is given below and added comment to so you learn easily.

Paste below this code in your template .

<?php acf_form_head(); ?>
<div id="primary" class="content-area">
    <div id="content" class="site-content" role="main">
   <?php while ( have_posts() ) : the_post(); ?>
    $title="Order ".$today;

        'post_id'       => 'new_post',
        //'post_title' => $title,
        'field_groups' => false,
        'fields'      => $fields,
        'new_post'      => array(
            'post_type'     => 'quick_order',
            'post_status'   => 'publish'
        'submit_value'  => 'Submit',
        'updated_message' => 'Thanks! We have received your request.',
        'return' => 'order-success',
    )); ?>
    <?php endwhile; ?>

Now send email using code below (paste below code in functions.php.

add_action('acf/save_post', 'my_save_post');
function my_save_post( $post_id ) {
    $post = get_post( $post_id );
    $name = get_field('customer_name', $post_id);
    $mobile = get_field('mobile_no', $post_id);
    $emailf = get_field('email', $post_id);
    $address = get_field('address', $post_id);
    $pickD = get_field('pickup_date', $post_id);
    $pickT = get_field('pick_up_time_slot', $post_id);
    $delivT = get_field('delivery_type', $post_id);
    $to = '[email protected]';
    $email='[email protected]';
    $headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
    $subject = "Quick Order";
    $body = '';
    $body .="Customer Name : ".$name."<br/>";
    $body .="Mobile No. : ".$mobile."<br/>";
    $body .="Email ID : ".$emailf."<br/>";
    $body .="Address : ".$address."<br/>";
    $body .="Pickup Date : ".$pickD."<br/>";
    $body .="Pickup Time : ".$pickT."<br/">;
    $body .="Delivery Type : ".$delivT."<br/";
    wp_mail($to, $subject, $body, $headers );
4 2 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments