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


How to add manual fields to an acf_form

  • 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 = '[email protected]';
    	$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);
  • 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?

  • Really great John. Thank you. Just what I needed and works perfectly! Love ACF!!

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

The topic ‘How to add manual fields to an acf_form’ is closed to new replies.