hello_hook.module
<?php
function hello_hook_init(){
//drupal_set_message("Hello module");
}
function hello_hook_menu(){
$items = array();
$items['hellopage'] = array(
'title' => 'My first item',
'description' => 'hello users',
'page callback' => 'drupal_get_form',
'page arguments' => array('hello_hook_showForm'),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function hello_hook_showForm(){
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#title' => 'Enter your name'
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'My button'
);
$form['#submit'][] = 'hello_hook_showForm_submit';
return $form;
}
function hello_hook_showForm_submit($form, &$form_state){
if($form_state['values']['name'] == ""){
form_set_error('name', 'name can not be null');
}else{
drupal_set_message("Button pressed ".$form_state['values']['name'] );
}
}
---------------------------------------------------------------------
hello_hook.info
name = Hello Hook
description = Print hello hook
core = 7.x
No comments:
Post a Comment