I know this might be a common issue and there are a lot of questions were asked about this point. But yet after searching all online tutorials including stackoverflow community, unfortunately i did not find what would help me.

I developed this piece of code to get CF7 fields submission and store it in a cookie to be fetched later on in another pages. I get “undefined error” ONLY for 3 fields of type “WPCF7 dynamic hidden” each time i press submit.

I tried all suggested solutions ( isset(), empty(), etc) but yet in vain.

add_action("wpcf7_before_send_mail", "wpcf7_save_data");
function wpcf7_save_data($wpcf7_data)
{
    $submission = WPCF7_Submission::get_instance();

    if ($submission)
    {
        $posted_data = $submission->get_posted_data();
    }

    $tour_date = $posted_data['tour-date'];
    $adult_no = $posted_data['no-adult'];
    $child_no = $posted_data['no-child'];
    $t_id = $posted_data['Gtour_id'];
    $t_price = $posted_data['Gtour_price'];
    $t_discount_price = $posted_data['Gtour_discount_price'];

    setcookie("bookinginfo[tour_date]", $tour_date, time() + (10 * 365 * 24 * 60 * 60) , "/", "tourexperts-eg.com", 1, true);
    setcookie("bookinginfo[tour_price]", $t_price, time() + (10 * 365 * 24 * 60 * 60) , "/", "tourexperts-eg.com", 1, true);
    setcookie("bookinginfo[tour_final_price]", $t_discount_price, time() + (10 * 365 * 24 * 60 * 60) , "/", "tourexperts-eg.com", 1, true);
    setcookie("bookinginfo[tour_id]", $t_id, time() + (10 * 365 * 24 * 60 * 60) , "/", "tourexperts-eg.com", 1, true);
    setcookie("bookinginfo[adult_no]", $adult_no, time() + (10 * 365 * 24 * 60 * 60) , "/", "tourexperts-eg.com", 1, true);
    setcookie("bookinginfo[child_no]", $child_no, time() + (10 * 365 * 24 * 60 * 60) , "/", "tourexperts-eg.com", 1, true);

    $wpcf7_data->skip_mail = true;
}

Read more here: Undefined index CF7 form submission fields


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: