drupal-7drupal-nodes

Drupal node checkbox checked even after deleteing from database table


I have written a code in drupal that after hitting node edit a delete query will run and unselect the radio button to display an alert each time. The query is working fine but the radio button got unchecked after second time reload. I want to uncheck that just after user click "Edit"

function debtcc_manage_node_prepare($node)
{
  $nid = $node->nid;
  if ($nid != null) {
    //field_cache_clear();
    $query = db_delete('field_data_field_change_updation_date')
      ->condition('entity_id',$nid)->execute();
    field_cache_clear();

  }
}

How can I achieve that? Is there any function in drupal to refresh the page automatically or other way?


Solution

  • Do a form alter and set default state for your field as uncheked:

    function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
    
    if ($form_id == 'YOUR_FORM_ID' && $form['nid']['#value'] != NULL) {
    
    $form['YOURFIELD'][LANGUAGE_NONE]['#default_value'] = 0;
    }
    }
    

    Upon clicking on edit checkbox will be unchecked and you already taken care of the database.