User login

Skip validation for a form element in Drupal

// we have to get out of validation somehow
// we have to get out of validation for an associated group somehow

You must join a group before posting on this web site.

Well, the nuclear option on case 'action_node_form': in my implementation of hook_form_alter works:

        $form['#validate'] = array();

Now is there a way to just skip, or preset, validation for one item in the form array?

drupal

ben-agaric: Is it possible to turn off validation of a specific form element with form_alter? (Override validation from another module.) In Drupal 5.

ben-agaric: Is there a way to turn off validation for a given form element? Drupal 5 and I've successfully merged two forms, so that you can create an organic group at the same time as the first post for that group ( http://dev.wsf2008.net/ ) but the only way I've been able to kill the "you must join a group" is with $form['#validate'] = array();
hunmonk: ben-agaric: you could try unsetting the validation handler, but that might also be overkill
[2:18pm] webchick left the chat room.
[2:19pm] dww: hunmonk: yeah, you most definitely bought yourself a hell of a lot more work, take it from me.
[2:19pm] ben-agaric: hunmonk: thanks, that's what my array() does I think, and yeah, I'd like it to do all the validation, except for one piece done by organic groups in nodeapi 'insert' -- if that provides another line of attack.

ben-agaric: just to report back to myself... validation can be successfully skipped by filling in dummy values... obvious, but organic groups was doing the validation in nodeapi and I wasn't sure what it corresponded to in the formapi... I think its funky 'og_groups_hidden' field
[2:38pm] ben-agaric: first post + organic group creation, in one form. With validation. Yay me.

Resolution

          // remove group choice, we'll pass this in directly
          // for reference: [og_nodeapi][visible][og_groups][#type] & [#value]
          unset($form['og_nodeapi']['visible']);
          // we have to get out of validation for an associated group somehow
          $form['og_nodeapi']['invisible']['og_groups'] = array(
            '#type' => 'value',
            '#value' => TRUE,
          );
          $form['og_nodeapi']['invisible']['og_groups_hidden'] = array(
            '#type' => 'value',
            '#value' => TRUE,
          );

I think only the second is absolutely needed, but better safe.

This is part of the conclusion to merging forms.

Searched words: 
drupal skip validation form element drupal skip validation for form element drupal validate form item nodeapi validate organic group Organic Groups merge form for first post

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.