0

Wp forms wpforms()->entry->update not working on page refresh , it only works when i do some change in wordpress dashboard (like clearing cache or updating any post) then only it is updating the data to database

function test35()
{

         global $wpdb;
     $tablename = $wpdb->prefix."testtable";
    $result = $wpdb->get_results ( "SELECT * FROM  $tablename" );
    foreach ( $result as $print )   {
    

    $entry_id = $print->jobid;
    $field_id = 57;
    include_once 'wpforms/src/Pro/Admin/Entries/Edit.php';
  

    // Get the current entry fields.
    $entry_fields_obj3 = wpforms()->entry->get( $entry_id );
    $entry_fields = wpforms_decode( $entry_fields_obj3->fields );

    
    if ( isset( $entry_fields[ $field_id ] ) ) {
        
        // Update the value of the specific field.
        $entry_fields[ $field_id ]['value'] = '1';
        $entry_fields[ $field_id ]['value_raw'] = '1';// Replace with your new value.
    }

    // Update the entry fields.
    
    $currnt_time = current_time( 'Y-m-d H:i:s' );
   $entry_data = [
                'fields' => wp_json_encode( $entry_fields ),    
                
            ];

            
    
    if(wpforms()->entry->update(
                $entry_id,
                $entry_data,
                '',
                'edit_entry',
                [
                    'cap' => 'edit_entry_single',
                ]
            )){echo "true";}else{echo "false";}
    
  
    
    $entry_fields_obj2 = wpforms()->get( 'entry_fields' );
    $dbdata_result    = $entry_fields_obj2->get_fields(
            [
                'entry_id' => $entry_id,
                'number'   => 1000,
            ]
        );
    
    $dbdata_fields    = [];
        if ( ! empty( $dbdata_result ) ) {
            $dbdata_fields = array_combine( wp_list_pluck( $dbdata_result, 'field_id' ), $dbdata_result );
            $dbdata_fields = array_map( 'get_object_vars', $dbdata_fields );
        }
    
    $dbdata_value_exist  = isset( $dbdata_fields[ $field_id ]['value'] );
    
    $form_id =  $dbdata_fields[1]['form_id'];
    $new_value = '1';
    $currnt_time = current_time( 'Y-m-d H:i:s' );
    
    // Add field data to DB if it doesn't exist and isn't empty.
    if ( ! $dbdata_value_exist) { 
        echo 'true';    
        $entry_fields_obj2->add(
                    [
                        'entry_id' => $entry_id,
                        'form_id'  => (int) $form_id,
                        'field_id' => (int) $field_id,
                        'value'    => $new_value,
                        'date'     => $currnt_time,
                    ]
                );  
    } 
    
    // Update field data in DB if it exists and isn't empty.
            if ( $dbdata_value_exist && $save_field['value'] !== '' ) {
                echo 'true';    
                $entry_fields_obj2->update(
                    (int) $dbdata_fields[ $field_id ]['id'],
                    [
                        'value' => $new_value,
                        'date'  => $currnt_time,
                    ],
                    'id',
                    'edit_entry'
                );
            }


    }

}

 add_action( 'wp', 'test35');
2
  • You'll have to ask the plugin's support team about this. Third-party plugin support is off topic here.
    – Pat J
    May 26 at 13:59
  • 1
    thanks for reply bro, i will ask plugin's support only
    – Ajay
    Jun 2 at 4:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.