drupaldrupal-formsdrupal-nodes

How to show / validate error of a node listing page


i am trying to save form state in database and want to view in a listing page with its error validation.

i.e, i want to validate a previously saved form state from my database.

this is a node type form .

i had already tried node_validate its not working because i fetch the data before submitting the node . so there is no nid and for that it is not working

and also tried drupal_validate_form but it is showing

[form_token] => The form has become outdated. Copy any unsaved work in the form below and then reload this page

EDIT
Any one with any help , "How to save a form inputs in data base and retrive it from database with out form submision.

Thank You In advance

Any help is most Appreciable.


Solution

  • If you look in Drupal Core, you see this in includes/form.inc at the drupal_validate_form function:

    if (isset($form['#token'])) {
        if (!drupal_valid_token($form_state['values']['form_token'], $form['#token'])) {
          $path = current_path();
          $query = drupal_get_query_parameters();
          $url = url($path, array('query' => $query));
    
          // Setting this error will cause the form to fail validation.
          form_set_error('form_token', t('The form has become outdated. Copy any unsaved work in the form below and then <a href="@link">reload this page</a>.', array('@link' => $url)));
    
          // Stop here and don't run any further validation handlers, because they
          // could invoke non-safe operations which opens the door for CSRF
          // vulnerabilities.
          $validated_forms[$form_id] = TRUE;
          return;
        }
      }`
    

    This shows that the "form has become outdated" message is being set here. So, you can make the isset($form[#token']) condition false by unsetting #token to prevent this message from appearing.

    All you have to do is load the form state you're going to validate, and call unset($form[#token']); before you call drupal_validate_form.