How add full entry data to another form in specil date?

hello
i have two form
first form id = 6
second form id = 21
same field with different field id
and i have gravity flow and gravity connector
but this plugins dont copy entries form 1 to form 21
in sepcial date field on form 6 , and i set and mapping fields but not working
can you help me guys ?
and i use this snippet code
but this code just copy first entry in specal date dont copy another entires :

// اطمینان از وجود توابع گرویتی فرم
if (!class_exists(‘GFForms’)) {
error_log(‘Gravity Forms is not active’);
return;
}

// ذخیره داده‌ها از فرم اول (ID: 6)
add_action(‘gform_after_submission_6’, ‘store_form_data’, 10, 2);
function store_form_data($entry, $form) {
$gender = rgar($entry, ‘10’); // فیلد رادیویی (آقای/خانم)
$name = rgar($entry, ‘5.6’); // نام خانوادگی (Last Name، زیرفیلد 5.6)
$mobile = rgar($entry, ‘3’); // موبایل
$date = rgar($entry, ‘67’); // تاریخ رفت (yyyy/mm/dd)

// بررسی مقادیر ورودی
if (empty($name)) {
    error_log('Last Name (field 5.6) is empty for entry ID: ' . $entry['id']);
}
if (empty($date)) {
    error_log('Date (field 67) is empty for entry ID: ' . $entry['id']);
    return;
}

// تبدیل تاریخ به timestamp (فقط تاریخ، بدون ساعت)
$timestamp = strtotime($date . ' 00:00:00');
if ($timestamp === false) {
    error_log('Invalid date format in form submission: ' . $date . ' for entry ID: ' . $entry['id']);
    return;
}

// ذخیره داده‌ها
$entry_data = array(
    'gender' => $gender,
    'name' => $name,
    'mobile' => $mobile,
    'date' => $date,
    'timestamp' => $timestamp,
    'processed' => false
);
update_option('scheduled_form_data_' . $entry['id'], $entry_data);
error_log('Form data stored for entry ID: ' . $entry['id'] . ' with date: ' . $date . ', Last Name: ' . ($name ?: 'empty'));

}

// بررسی و کپی داده‌ها با لود صفحه اصلی
add_action(‘wp’, ‘check_scheduled_form_submission’);
function check_scheduled_form_submission() {
if (is_front_page()) { // فقط در صفحه اصلی اجرا شود
global $wpdb;
$current_time = current_time(‘timestamp’);
$current_date = strtotime(date(‘Y-m-d 00:00:00’, $current_time)); // تاریخ امروز بدون ساعت


    // دریافت تمام داده‌های ذخیره‌شده
    $options = $wpdb->get_results("SELECT * FROM $wpdb->options WHERE option_name LIKE 'scheduled_form_data_%'");
    error_log('Checking scheduled form submissions. Found ' . count($options) . ' entries.');

    foreach ($options as $option) {
        $entry_data = maybe_unserialize($option->option_value);
        $entry_id = str_replace('scheduled_form_data_', '', $option->option_name);

        // بررسی اینکه تاریخ اجرا رسیده و هنوز پردازش نشده
        if ($entry_data['timestamp'] <= $current_date && !$entry_data['processed']) {
            $form_id = 21; // ID فرم دوم

            $form_data = array(
                'input_1' => $entry_data['gender'], // فیلد رادیویی (آقای/خانم)
                'input_3_6' => $entry_data['name'], // نام خانوادگی (زیرفیلد Last Name)
                'input_4' => $entry_data['mobile'], // موبایل
                'input_5' => $entry_data['date'], // تاریخ رفت
            );

            // ارسال فرم دوم با Gravity Forms API
            $result = GFAPI::submit_form($form_id, $form_data);
            if (is_wp_error($result)) {
                error_log('Failed to submit form 21 for entry ID: ' . $entry_id . ' - Error: ' . $result->get_error_message());
            } else {
                error_log('Form 21 submitted successfully for entry ID: ' . $entry_id . ', Last Name: ' . ($entry_data['name'] ?: 'empty'));
                // علامت‌گذاری به‌عنوان پردازش‌شده
                $entry_data['processed'] = true;
                update_option('scheduled_form_data_' . $entry_id, $entry_data);
            }
        }
    }
}

}
please help me guys

Hi Ali,

It’s hard to figure out exactly what is going wrong from the context you’ve provided. However, there might be a timing issue.

The $date param will most likely be stored without a timezone, so your $entry[‘timestamp’] will be in UTC, while current_time has a timestamp that is adjusted to the timezone of your WordPress installation. So there might be a mismatch there.

Additionally, if you set a date in the future on that field, your logic will not retrieve that entry today, but on a day AFTER that date. I’m not sure if that is what you are going after, but that could be part of the issue you are seeing.

Hope this helps you out. Otherwise, please provide some extra context, including multiple entries with actual data. That might shed some light on the issue.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.