• I need get data from select value and send it do TablePress


    dd_action('wpcf7_before_send_mail', 'update_user_tablepress_entry_cf7');
    function update_user_tablepress_entry_cf7($contact_form) {
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
    $data = $submission->get_posted_data();

    // Získajte aktuálneho používateľa
    $current_user = wp_get_current_user();
    $user_id = $current_user->ID;

    // Získajte hodnoty z formulára
    $name = sanitize_text_field($data['your-name']);
    $email = sanitize_email($data['your-email']);
    $gold = sanitize_text_field($data['gold']);
    $silver = sanitize_text_field($data['silver']);

    // Logujte údaje pre debugging
    error_log('CF7 Submission Data: ' . print_r($data, true));
    error_log('Current User ID: ' . $user_id);
    error_log('Form Data: Name: ' . $name . ', Email: ' . $email . ', Gold: ' . $gold . ', Silver: ' . $silver);

    // Získajte ID tabuľky z TablePress
    $table_id = '4'; // ID tabuľky, ktorú ste vytvorili v TablePress

    // Získajte aktuálnu tabuľku z TablePress
    $table = TablePress::$model_table->load($table_id);

    // Skontrolujte, či už existuje záznam pre používateľa
    $updated = false;
    foreach ($table['data'] as &$row) {
    if ($row[0] == $user_id) {
    // Aktualizujte záznam
    $row[1] = $name;
    $row[2] = $gold;
    $row[3] = $silver;
    $updated = true;
    break;
    }
    }

    if (!$updated) {
    // Pridajte nový záznam
    $table['data'][] = array($user_id, $name, $email, $gold, $silver);
    }

    // Uložte tabuľku späť
    TablePress::$model_table->save($table);

    // Logujte úspešné uloženie
    error_log('TablePress data updated successfully');
    }
    }

    ERROR LOG:
    [14-Jun-2024 12:31:30 UTC] CF7 Submission Data: Array
    (
    [user_id] =>
    [your-name] => MisoL
    [your-email] => mi*****@gmail.com
    [gold] => Array
    (
    [0] => CHORVÁTSKO
    )

    [silver] => Array
    (
    [0] => FRANCÚZSKO
    )

    )

    The page I need help with: [log in to see the link]

The topic ‘How do I get dropdown selected value?’ is closed to new replies.