2017 © Pedro Peláez
 

drupal-module drupal_magic_forms

Because Drupal Forms blow.

image

matthewbaggett/drupal_magic_forms

Because Drupal Forms blow.

  • Saturday, February 6, 2016
  • by matthewbaggett
  • Repository
  • 3 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Magic Form Objects

A slightly less hateful implementation of form handling for Drupal 7., (*1)

Because we all know drupal forms blow., (*2)

Support many form field types: * Button * File * Group * Hidden * Input * Radios * Select * Textarea * Date * Ranges (thanks Jason!) * Multiple selection Radios * Switches (Jason again), (*3)

Bonus features: * Data Tables. * Labels, (*4)

Validators

Example with validators:, (*5)

$form = new magic_form('my-form');
$form
  ->add_field(
    magic_form_field_text::factory('some-field', 'Some Field', 'Some Default')
      ->add_validator(new magic_form_validator_is_valid_phonenumber())
      ->add_validator(new magic_form_validator_is_valid_email())
  )->add_field(
    magic_form_field_text::factory('other-field')
      ->add_validator(new magic_form_validator_is_less_than(100))
      ->add_validator(new magic_form_validator_is_greater_than(50))
  )->add_field(
    magic_form_field_text::factory('other-field')
      ->add_validators(
        new magic_form_validator_is_less_than(100),
        new magic_form_validator_is_greater_than(50),
        new magic_form_validator_regexp('REGEXP_GOES_HERE')
      )
  )->add_fields(
    magic_form_field_text::factory('some-field', 'Some Field', 'Some Default')
      ->add_validator(new magic_form_validator_is_valid_phonenumber())
      ->add_validator(new magic_form_validator_is_valid_email()),
    magic_form_field_text::factory('some-field', 'Some Field', 'Some Default')
      ->add_validator(new magic_form_validator_is_valid_phonenumber())
      ->add_validator(new magic_form_validator_is_valid_email()),
    magic_form_field_text::factory('some-field', 'Some Field', 'Some Default')
      ->add_validator(new magic_form_validator_is_valid_phonenumber())
      ->add_validator(new magic_form_validator_is_valid_email()),
    magic_form_field_text::factory('some-field', 'Some Field', 'Some Default')
      ->add_validator(new magic_form_validator_is_valid_phonenumber())
      ->add_validator(new magic_form_validator_is_valid_email())
  );

  $form->submit(function (magic_form $form) {
      drupal_set_message("Submit happened in form {$form->magic_form_id} / {$form->form_id}");
  });

  // Check to see if an earlier, updated build of this form exists.
  magic_form::check_for_updated_form($form);

  // render the form.
  return $form->__toString();

The Versions

06/02 2016

dev-master

9999999-dev

Because Drupal Forms blow.

  Sources   Download

GPLv2

The Requires