• I am trying to add a custom field to my contact form 7 post data. Here is my code:

    add_filter( 'wpcf7_posted_data', 'action_wpcf7_posted_data', 10, 1 );
    
    function action_wpcf7_posted_data( $array ) { 
    $array['paymentoption'] = "test";
    
    return $array;
    }
    

    However, the array is not changed. When I submit the form , the value of “paymentoption” is not changed to test.

    I also tried $array['paymentoption'][0] = "test";

    That did not help.

    Any clues?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tsjippy

    (@tsjippy)

    I tried something totally different to achieve the same result but that fails as well:

    codex

    So I have added <input type="hidden" name="action" value="add_foobar">to the form, and this to my functions.php:

    function prefix_admin_add_foobar(){ 
        status_header(200);
        var_dump($_POST);
        // wp_redirect( 'http://any.url/',302 ); 
        die("Server received '{$_POST['name']}' from your browser.");
    
    }
    
    add_action( 'admin_post_add_foobar', 'prefix_admin_add_foobar' );
    add_action( 'admin_post_nopriv_add_foobar', 'prefix_admin_add_foobar' ); // this is for non logged users

    does not work…

    Thread Starter tsjippy

    (@tsjippy)

    This however works:
    <form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>?action=add_foobar" method="post">

    But I have no clue how to add that to a contact form

    Thread Starter tsjippy

    (@tsjippy)

    Now have the same headers:

    <form action="https://www.tastedelft.nl/wp-admin/admin-post.php?action=add_foobar" method="post" class="wpcf7-form" novalidate="novalidate">
    

    My custom form does a redirect, the Contact form 7 does not.

    my whole custom, working form:

    <form action="https://www.tastedelft.nl/wp-admin/admin-post.php?action=add_foobar" method="post" class="wpcf7-form" novalidate="novalidate">
       <input name="name" placeholder="Enter email" type="text">
       <button type="submit" class="btn btn-primary">Submit</button>
    </form>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘‘wpcf7_posted_data’ not working?’ is closed to new replies.