PHPJavascript

Web Development Guide – My Personal Library of Tutorials and Scripts

Drupal webform validate either fields

February22

I am using webforms and I have three fields were either one of em should be filed.

Use the “additional validation” input box in the form “configuration”.

The code is following:

<?php
$book= $form_values['submitted'][11];
$author= $form_values['submitted'][12];
$isbn= $form_values['submitted'][13];

if (($book == NULL) AND ($author == NULL) AND ($isbn == NULL))
{
form_set_error(”, t(’Please enter either Book Title or Author or ISBN.’));
}
?>

The 11, 12 and 13 is the field id of your input fields. To find the field IDs mouse over the “edit” link next to your fields in the “Form Components”.

posted under Drupal
3 Comments to

“Drupal webform validate either fields”

  1. On February 28th, 2010 at 9:47 pm Felipe Says:

    Hi, How do I alter action in a form, created with webform ?

    Thanks

  2. On March 3rd, 2010 at 10:52 pm Mike Ryan Says:

    Felipe,

    You should be able to find the webform’s form id by looking at the source code when you’re viewing that form. Once you have that you can use either hook_form_alter() or hook_form_FORM_ID_alter() to make changes to the form.

    http://api.drupal.org/api/function/hook_form_alter

    -Mike

  3. On June 26th, 2010 at 2:39 am Ibrahim Says:

    Thank you. wondering if there is any way to hide some fields from some role.

Email will not be published

Website example

Your Comment:

 

12,829 spam comments
blocked by
Akismet