Home Forums ACF PRO Send email through frontend form with fields


Send email through frontend form with fields

  • Hi, I’m trying to create a form in a product on the frontend side, where:

    1. on backend, the administrator creates a product (a cpt) and choose some colors from a list of colors (field type: checkbox)
    2. on frontend, using acf_form(), a form with the above colors is shown, so a client can pick one of them
    3. on submitting the form, an email is sent to the admin, with the color chosen by the client (so the value of the field)

    No problem on 1 and 2, but 3 is where some trouble begins. I can make the form send the email, but I can’t output the field I need (the color chosen in step 2). I can output a field that is not on the form (so it’s simply some data shown, like a SKU code), but nothing else.

    My code is:


    function customize_form_init() {
        // Check function exists.
        if( function_exists('acf_register_form') ) {
    			'post_id'		=> 'new_post',
    			'new_post'		=> array(
    				'post_type'		=> 'richieste_club',
    				'post_status'	=> 'publish'
    			'id'		    	=> 'form_customize',
    			'field_groups'		=> array(801),
    			'submit_value'		=> __("Invia richiesta di preventivo", 'acf'),
    			'updated_message' 	=> __("Richiesta inviata", 'acf'),
    add_action('acf/init', 'customize_form_init');


    function club_save_post($post_id) {
    	// Bail early if editing in admin
    	if( is_admin() ) {		
    	$post 			= get_post($post_id);
    	$custom 		= get_post_custom($post_id);
    	$coccarda 		= get_field('club_custom_coccarda');
    	$codice  		= get_field('club_codice');
    	$to 	 		= '[email protected]';
    	$subject 		= 'Richiesta sezione Club';
    	$email_body 	        = 'Numero: '.$coccarda.'<br>Codice: '.$codice;		
    	wp_mail($to, $subject, $email_body);
    add_action('acf/save_post', 'club_save_post', 20);

    In this code, $coccarda is the field which is chosen on step 2 (and doesn’t show on the email), whereas $codice is a text field entered by the administrator on the product, and it correctly shows on the email.

    Thanks in advance!

Viewing 1 post (of 1 total)

The topic ‘Send email through frontend form with fields’ is closed to new replies.