Home Forums Front-end Issues How to add manual fields to an acf_form


How to add manual fields to an acf_form

    • Julien

    • June 8, 2018 at 5:58 pm

    Hello, I try to create a simple contact form with ACF and send a mail, here is my code in the page:

    <?php acf_form_head(); ?>
    <?php acf_form(); ?>

    and in function.php:

    add_action('acf/save_post', 'my_save_post');
    function my_save_post() {
    	if( is_admin() ) {
    	$name = get_field('name');
    	$email = get_field('email');
    	// email data
    	$to = '';
    	$headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
    	$subject = 'answer';
    	$body = 'general text';
    	wp_mail($to, $subject, $body, $headers );

    It works fine but I want to add a select field with values from database in the form (I mean a non-ACF field, I want to add it with code), but I don’t find a way to do that, any ideas?
    Thanks a lot!

  • You would need to use a select field and you can populate the field

    You can also have ACF output the form without form tags

    <!-- you need to supply the form tags with all correct attributes -->
    <form><!-- add correct attributes to this tags -->
    <!-- add a field before or after acf fields -->
    <input type="text" name="my-field" value="" />
      // call acf form
      acf_form('form' => false);
    • Julien

    • June 8, 2018 at 11:52 pm

    That’s great, thanks a lot for your help !

  • John what if we only want to include custom fields and no fields from acf_form, how can we do that?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.