Change Boolean field status on clicking submit button I have placed an additional button to the term edit page, and when the user clicks on the additional ("Archieve") button, the status of the boolean field should change from 0 to 1 in the database.

I have written the following code for achieving the above:

function security_settings_form_alter(&amp;$form, &amp;$form_state, $form_id)
{
    if($form_id == 'taxonomy_form_term')
    {
        dpm($form);
        $form['actions']['push'] = array(
            '#type' =&gt; 'submit',
            '#value' =&gt; t('Archieve'),
            '#submit' =&gt; array('my_custom_submit_function'),
            '#weight' =&gt;25
        );
    }
}


function my_custom_submit_function($form, &amp;$form_state)
{
    $form_state['values']['field_test_button']['und'][0]['value']=1;
    db_query("UPDATE {field_data_field_test_button} SET field_test_button_value = :val WHERE entity_id = :eid",
             array(':val' =&gt; $form_state['values']['field_test_button']['und'][0]['value'], ':eid' =&gt; $form_state['values']['tid']));
    drupal_set_message(t('Your form has been archieved.'));
}


The above functionality is working fine.

But if the user clicks on the same archieve button again, its status should change from 1 to 0 in the database.

Any idea how can achieve this?
I would do it.

function my_custom_submit_function($form, &amp;$form_state)
{
    //if value is 1, then value=0
    if ($form_state['values']['field_test_button']['und'][0]['value']==1) {
        $form_state['values']['field_test_button']['und'][0]['value']=0;
    }
    else 
        //if value is 0, then value=1
        if ($form_state['values']['field_test_button']['und'][0]['value']==0) {
            $form_state['values']['field_test_button']['und'][0]['value']=1;
        }
    //$form_state['values']['field_test_button']['und'][0]['value']=1;
    db_query("UPDATE {field_data_field_test_button} SET field_test_button_value = :val WHERE entity_id = :eid",
             array(':val' =&gt; $form_state['values']['field_test_button']['und'][0]['value'], ':eid' =&gt; $form_state['values']['tid']));
    drupal_set_message(t('Your form has been archieved.'));
}