![]() ![]() Let's change the email field to accommodate users that prefer to be anonymous. While the OR operator is implied by using an non-associative array, the XOR operator needs to be explicitly defined with an array item with the string 'xor'. There is also a special syntax for the exclusive or (XOR) operator, which one or the other condition is true, but not both. * or anonymous is checked and method is email. * the name is filled and the method is email, ':select' => array('value' => 'email'),įor OR conditions, use an non-associative array by wrapping each group of conditions in the array() function. and 'email' is selected for the preferred method of contact field Show the email field when the name field is filled We can also define multiple conditions to show the email field, only when the name field is filled and email is the preferred method of contact. '#title' => t('I prefer to remain anonymous'), Uncheck anonymous field when the name field is filled. Hide name field when the anonymous checkbox is checked. We can simply use the invisible state to hide the name field when the anonymous checkbox is checked, and conversely keep the anonymous checkbox unchecked if the name field is filled. We would like the name field and anonymous checkbox to work together. Here is a simple form to collect some basic personal info from a user. Starting with a simple form, let's look at a few examples. Wunderkraut also has a great article, quoting our Co-Founder and CEO Jeff Robbins breaking down the states into two categories, "the ones that trigger change in others" and "the ones that get applied onto elements". ![]() All the available states and remote conditions are defined in the drupal_process_states(). enabled, disabled, checked, unchecked), while a remote condition is the state of an element to trigger a change in different element. A state is a property that can be applied to a form element (i.e. It eliminates inconsistencies by translating simple form element properties into standardized JavaScript code.Įach form field consist of states and remote conditions that define the properties of the field. For most common Form UI tasks, the #states system eliminates the need to write custom JavaScript. Form API #states allow us to create form elements that change state (show, hide, enable, disable, etc.) depending on certain conditions-for example, disabling one field based on the contents of another. One of its most powerful features, though, isn't very well known: the #states system. Drupal's Form API helps developers build complex, extendable user input forms with minimal code.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |