By nhero on
I have created a form and would like to add a hook_block so I can use the from as a block.
<?php
// $Id$
/**
* @file
* Play with the Form API.
*/
/**
* Implementation of hook_menu().
*/
function formexample_menu() {
$items['formexample'] = array(
'title' => 'View the form',
'page callback' => 'formexample_page',
'access arguments' => array('access content'),
);
return $items;
}
/**
* Menu callback.
* Called when user goes to http://example.com/?q=formexample
*/
function formexample_page() {
$output = t('This page contains our example form.');
// Return the HTML generated from the $form data structure.
$output .= drupal_get_form('formexample_nameform');
return $output;
}
/**
* Define a form.
*/
function formexample_nameform() {
$form['user_name'] = array(
'#title' => t('Your Name'),
'#type' => 'textfield',
'#description' => t('Please enter your name.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
return $form;
}
/**
* Validate the form.
*/
function formexample_nameform_validate($form, &$form_state) {
if ($form_state['values']['user_name'] == 'King Kong') {
// We notify the form API that this field has failed validation.
form_set_error('user_name',
t('King Kong is not allowed to use this form.'));
}
}
/**
* Handle post-validation form submission.
*/
function formexample_nameform_submit($form, &$form_state) {
$name = $form_state['values']['user_name'];
drupal_set_message(t('Thanks for filling out the form, %name',
array('%name' => $name)));
}
/**
* Implementation of hook_block()
*/
function formexample_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Goodreads Bookshelf');
$blocks['content'] = ?????
return $blocks;
}
}
what do I need to put for $blocks['content'] = to have the form show up as a block?
Edited by: VM; added code tags and moved to appropriate forum
Comments
Please, surround your code in
Please, surround your code in code tags: <code></code>
Contact me to contract me for D7 -> D10/11 migrations.
Here's a tutorial on how to
Here's a tutorial on how to create blocks: http://drupal.org/node/206758
Contact me to contract me for D7 -> D10/11 migrations.
By drupal_get_form
You can do it by using the function drupal_get_form(FORMID). In your case it should be