• Resolved mcbmcb0

    (@mcbmcb0)


    Hello
    I need to know which wpcf7 form was submitted.
    is there a way to submit the form’s id or title within the form, preferably as a hidden field? so I can include it in the email and store in db with flamingo / others?

    thanks!

    • This topic was modified 4 years, 10 months ago by mcbmcb0.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Special Mail Tags will let you easily see which CF7 form was submitted.

    If you want more detailed control Getting Default Values from the Context may assist.

    Thread Starter mcbmcb0

    (@mcbmcb0)

    Thanks Neil, this is promising. but so far I can’t get a result using ‘getting context values’ with post or post-meta.
    On form submit I can see ‘_wpcf7’ is posted, (ie, a key in $_POST) so have tried this:
    [hidden form-id-post default:post "_wpcf7"]
    but only the string ‘_wpcf7’ is returned..
    Also I can see ‘_wpcf7’ in the wp db post_meta table showing the form id so tried this:
    [hidden form-id2 default:post_meta "_wpcf7"]
    but again the string ‘_wpcf7’ is returned.

    can you see what i am doing wrong?
    is there a list of CF7 posts or post_meta data somewhere

    Thanks

    Thread Starter mcbmcb0

    (@mcbmcb0)

    no answers? so here what i did: i couldn’t get the above to work for me so added my own tag in the theme’s functions.php then put [form-info] in the form:

    add_action( 'wpcf7_init', 'custom_add_form_tag_id' );
    function custom_add_form_tag_id() {
        wpcf7_add_form_tag( 'form_info', 'custom_id_form_tag_handler' ); // "clock" is the type of the form-tag
    }
    function custom_id_form_tag_handler( $tag ) {
        
    	$wpcf7 = WPCF7_ContactForm::get_current();
    	$form_id = $wpcf7->id();
    	$form_title = $wpcf7->title();
    	$form_name = $wpcf7->name();
    	return "<input type='hidden' name='form_id' value='$form_id' />"
    		. "<input type='hidden' name='form_title' value='$form_title' />"
    		. "<input type='hidden' name='form_name' value='$form_name' />";
    }

    HTH

    How about the following, this should work:

    Child Theme functions.php:

    //Contact Form 7 Custom Output
    add_filter('wpcf7_posted_data', function($data) {
      	$form = wpcf7_get_current_contact_form();
    	$data['form-id'] = $form->id()
    }
    );

    Then in your form template:

    [hidden form-id]

    Then in your email template

    [form-id]

    • This reply was modified 4 years, 9 months ago by Conor_Hyland.
    • This reply was modified 4 years, 9 months ago by Conor_Hyland.

    Just spotted a mistake:
    $data['form-id'] = $form->id()
    should be:
    $data['form-id'] = $form->id();

    Don’t forget the line:

    return $data;

    //Contact Form 7 Custom Output
    add_filter('wpcf7_posted_data', function($data) {
    
      	$form = wpcf7_get_current_contact_form();
    	$data['form-id'] = $form->id();
    	return $data;
    }
    );

    Then in your form template:

    [hidden form-id]

    Then in your email template:

    [form-id]

    Thread Starter mcbmcb0

    (@mcbmcb0)

    thanks Connor – lots of ways to get this done.
    the return $data is a good reminder for the filter

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘submit hidden form id or form title within the form?’ is closed to new replies.