Paste: for vasea :-)

Author: ina
Mode: php
Date: Wed, 3 Nov 2010 09:29:22
Plain Text |
<?php

///**
//* Implementation of hook_node_info().
//*/

function A_node_info() {
    return array(
            'node_example' => array(
                    'name' => t('contentA'),
                    'module' => 'A',
                    'description' => "This is a test node type with a few fields.",
            )
    );
}

///**
//* Implementation of hook_perm().
//*/

function A_perm() {
    return array('access test content');
}

///**
//* Implementation of hook_access().
//*/

function A_access($op, $node) {
    global $user;

    if ($op == 'create') {
        // Only users with permission to do so may create this node type.
        return user_access('create test');
    }

    // Users who create a node may edit or delete it later, assuming they have the
    // necessary permissions.
    if ($op == 'update' || $op == 'delete') {
        if (user_access('edit own test') && ($user->uid == $node->uid)) {
            return TRUE;
        }
    }
}

///**
//* Implementation of hook_form().
//*/

function A_form(&$node, $form_state) {
// Define a fieldset.
    $form['test'] = array(
            '#type' => 'fieldset',
            '#title' => t('Simple form'),
            '#tree' => true,
    );

//define a multiple select
    $form['test']['domains'] = array(
            '#type' => 'select',
            '#title' => t('Domains'),
            '#options' => array(
                    '0' => t('Informatics'),
                    '1' => t('Matematics'),
                    '2' => t('Foreign languages'),
            ),
            '#multiple' => true,
            '#required' => true
    );

//define radio button
    $form['test']['gender'] = array(
            '#type' => 'radios',
            '#title' => t('Gender'),
            '#options' => array(t('Male'), t('Female')),
    );

// Define a textarea .
    $form['test']['note'] = array(
            '#type' => 'textarea',
            '#title' => t('Notes'),
            '#required' => true
    );

//define input field for email
    $form['test']['email'] = array(
            '#type' => 'textfield',
            '#title' => t('E-mail'),
            '#default_value' => '',
            '#size' => 60,
            '#required' => true,
    );


//define one checkbox
    $form['test']['agree'] = array(
            '#type' => 'checkboxes',
            '#options' => array(0 => t('I agree')),
    );
// For convenience, save the node ID.
    $form['test']['nid'] = array(
            '#type' => 'value',
            '#value' => $node->nid,
    );

// Define a submit function.
    $form['test']['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Update'),
    );
    return $form;
}

function A_form_validate($form, &$form_state) {
    die('we got here');
    if ($form_state['values']['test']['gender'] == 'Male') {
        form_set_error('', t('You must select female'));
    }
}

New Annotation

Summary:
Author:
Mode:
Body: