Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- form_fun.module file - this line does not appear in the code, obviously.
- <?php
- /*
- * Implements form hook_menu().
- */
- function form_fun_menu() {
- $items = array();
- $items['form_fun/cake'] = array(
- 'title' => 'Cake or Pie?',
- 'page callback' => 'form_fun_cake_page',
- 'access arguments' => array('access content'),
- 'file' => 'form_fun.cake.inc',
- 'weight' => 1,
- );
- return $items;
- }
- form_fun.cake.inc file - also just a note for reference.
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- function form_fun_cake_page() {
- return drupal_get_form('form_fun_cake');
- }
- function form_fun_cake(&$form_state) {
- $form = array();
- $form['choice'] = array(
- '#type' => 'select',
- '#title' => t('Cake or pie?'),
- '#description' => t('Would you like cake or pie?'),
- '#options' => array(
- 'cake' => t('Cake please'),
- 'pie' => t('Pie I guess'),
- ),
- '#default' => 'cake',
- '#required' => TRUE,
- );
- $form['buttons']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
- $form['buttons']['unsure'] = array(
- '#type' => 'submit',
- '#value' => t('Equivocate'),
- '#submit' => array('form_fun_cake_unsure'),
- '#validate' => array(),
- );
- return $form;
- }
- function form_fun_cake_validate(&$form, &$form_state) {
- if($form_state['values']['choice'] == 'cake') {
- form_set_error('choice', t('We are out of cake.'));
- }
- }
- function form_fun_cake_submit(&$form, &$form) {
- dsm($form_state['values']);
- $form_state['redirect'] = '';
- }
- function form_fun_cake_unsure(&$form, &$form_state) {
- drupal_set_message(t('Make up your mind.'), 'warning' );
- }
- form_fun.info - file
- name = Form FunApi Demonstration
- description = Demonstrate the use of Form API.
- core = 7.x
- files[] = form_fun.cake.inc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement