Mymodule (folder)
- mymodule.info
- mymodule.module
- mymodule.inc
If you check this article out, can remember what the system of drupal's work. When we code, we call the function which will use. Well, then code your mymodule.inc and mymodule.module pages:
mymodule.module page
function honda_menu() { $items['honda/hrv'] = array( 'title' => 'Honda HR-V', 'page callback' => 'honda_form', 'access arguments' => array('access content'), 'file' => 'honda.inc', ); return $items; }
As you see the bold row's got our function for the module with "page callback". honda_form() function is in;
mymodule.inc page
function honda_form() { return drupal_get_form('form_for_honda'); //This is the function that will use } function form_for_honda($form_state) { $form['text'] = array( '#type' => 'textfield', //Input type '#title' => t(Write something..'), Input label ); $form['Okey'] = array( '#type' => 'submit', //Input type '#value' => 'I am Ok!', //Button value ); return $form; }
When we go to honda/hrv direction, we're going to see it like down here;
Output |
Well done! Our form is ready to use. I've just added a textfield and submit button. If you want to add something else, you should add elements for array. For example;
'#type' => 'checkbox', '#type' => 'fieldset', '#type' => 'file', '#type' => 'radios',
If you want to see more information about Drupal forms API, you can visit forms API.
We'll see you next article!