0

Issue: When create a node and node publish check box is checked, all validation should work (it's working fine). but when create a node and node publish check box is not checked , then all validation should skip.

function mymodule_form_alter(&$form, &$form_state) {
   array_unshift($form['#validate'], 'mymodule_reqursive_unrequired');  
}

function mymodule_reqursive_unrequired(&$form, &$form_state) {
    // print_r($form);die;
    $form['actions_copy']['submit']['#limit_validation_errors'] = array();
    $form['actions']['submit']['#limit_validation_errors'] = array();

    $form['title']['#required'] = FALSE;
    $blog_images = $form['field_image_blog'][LANGUAGE_NONE];
    $form['field_page_title'][LANGUAGE_NONE][0]['#required'] = FALSE;
    foreach($blog_images as $image_k => $blog_image) {
      $form['field_image_blog'][LANGUAGE_NONE][$image_k]['#required'] = FALSE;
    }
    // print_r($form);die;
}

Any suggestion ?

  • Is there any reason why you would want to avoid a non published node is validated? It is only when a node is saved that the node is validated. If you want to save a draft, there are modules for that already. – kiamlaluno Apr 23 '15 at 10:20
  • yes, want to save as draft without any validation for unpublished content. – bisw Apr 23 '15 at 10:26
  • Then, there are modules already doing that; there isn't the need to write a module just for that. – kiamlaluno Apr 23 '15 at 10:28
  • are you sure the node which is not saved yet that will not be validated? i am already using revisioning module for moderation work. bdw can you mention the module name – bisw Apr 23 '15 at 10:31
  • this functionality is not working for saved content also. ..:( Any suggestion please... – bisw Apr 23 '15 at 10:35
0

After a lot of debugging and search i get the solution.

function mymodule_reqursive_unrequired(&$form, &$form_state) {
    // print_r($form);die;
   if(!$form_state['values']['status']) {
     drupal_static('form_set_error', NULL, TRUE);
     drupal_get_messages();
   }  
    // print_r($form);die;
}

for reference check it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.