mercredi 3 juin 2015

If statement not working with radio button

I am trying to create an entry in a second form when a value in a first form is updated to "Approved". The field containing approved is a radio button field.

I am able to create the entry as desired using the code below if I eliminate the If statement and use frm_create_entry action. However the code below does not work.

add_action('frm_after_update_entry', 'update_or_create_entry4', 30, 2);

function update_or_create_entry4($entry_id, $form_id){

    if ( $form_id == 2 ) {//Change 430 to the ID of Form A

        global $wpdb, $frmdb;

        $form2 = '104';//Change 480 to the ID of Form B
        $hours = $_POST['item_meta'][85];
        $badge1 = $_POST['item_meta'][6806];
        // $badge1 = FrmProEntriesController::get_field_value_shortcode(array('field_id' =>                 732, 'entry_id' => $_POST['item_meta'][6806]));
        $RDOdate = $_POST['item_meta'][90];
        $division = $_POST['item_meta'][6920];
        $starttime = $_POST['item_meta'][91];
        $startdate = $_POST['item_meta'][90];
        // $approved = $_POST['item_meta'][96];
        $approved = $(input[name='item_meta[96]']);
        $user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $frmdb->entries WHERE id=%d", $entry_id));

        if ( !$user ) 
            return;

        if ($approved === "Approved") {
            //create entry
            FrmEntry::create(array(
                'form_id' => $form2,
                'item_meta' => array(
                    6921 => $hours,
                    6888 => $user,//Change 48269 to the ID of the userID field in Form B
                    6854 => $RDOdate, //needs to have the value of the date of RDO
                    6891 => 'RDO',
                    6895 => $division, //needs value from division field
                    6856 => $starttime,
                    6854 => $startdate,
                    6943 => $badge1, //change 48262 to the ID of the field you want to populate (in Form B)
                ),
            ));
        }
    }
}

I am very new to coding, thank you in advance.

Aucun commentaire:

Enregistrer un commentaire