I'm trying to create a custom form displayed inside of a block.
Here is my code: [edited]
<?php
/*
* Creating custom form to edit/delete nodes
*/
function custom_block_settings_formedit_node_block_info($form, &$form_state){
$form['node-id'] = array(
'#type' => 'textfield',
'#title' => 'Node Number',
'#maxlength' => 15,
'#size' => 15,
'#required' => TRUE,
);
$form['edit-delete']$blocks['edit_node'] = array(
'#type' => 'radios',
'#options''info' => arrayt('edit' =>'Custom 'Edit',Block 'delete'to =>allow 'Delete'edit/delete/copy'),
'#required' => TRUE,
);
$form['save'] = array(
'#type''status' => 'submit'1,
'#value''region' => 'Submit''Primary',
'#submit''weight' => array('custom_block_form_submit')0,
'#validate''visibility' => array('custom_block_form_validate')BLOCK_VISIBILITY_LISTED,
);
return $form;$blocks;
}
/*
* running validation on theImplements formhook_block_view: tosets verifyhow nodethe idblock is correct
*displayed
*/
function custom_block_settings_form_validateedit_node_block_view($form,$delta &$form_state,= &$node''){
ifswitch (($node->nid$delta) != ($form_state['value']['node-id']));{
form_set_error('node-id', 'Please enter a valid node-id');
}
/*
*case Create'edit_node' block:
*/
function custom_block_settings_block_info(){
$blocks = array();
$blocks['custom_block_settings']$block['subject'] = array(
'info' => t('Custom block'),
'region' => 'sidebar_second',
'status' => TRUE,
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => variable_get('hospitalist-schedule', NULL),
);
return $blocks;
}
function custom_block_settings_block_view($delta = ''){
$block =-'Edit array(Nodes');
switch ($delta) {
case 'custom_block_delete':
$block['subject']$block['content'] = tdrupal_get_form('Custom Block''edit_node_form');
$block['content'] = drupal_get_form('custom_block_settings_form');
break;
}
return $block;
}
I also have ran drush block-show to see if the block has shown up"(ref: Registered custom block not showing up):
Module Delta Region Weight
block 4 sidebar_second 0/*
block 1 -1 * implements custom form/creating custom form for drupal_get_form named 0above.
block 2 -1 0*/
block 3 -1 0
backup_migrate quick_backup -1 function edit_node_form($form, &$form_state) 0{
calendar calendar_legend $form['node-1 id'] = 0array(
comment recent -1 '#type' => 0'textfield',
context_ui editor -1 '#title' => t('Enter the Node 0ID'),
context_ui devel '#max-1 length' => 08,
fullcalendar_legend fullcalendar_legend -1 '#required' => 0TRUE,
logintoboggan logintoboggan_logged_in -1 0);
menu devel $form['edit-1 node'] = 0array(
node syndicate -1 '#type' => 0'radios',
node recent -1 '#title' => t('Select 0Action'),
search form -1 '#options' => array(t('edit'), t('delete'), -1t('copy')),
shortcut shortcuts -1 0);
system main content $form['submit'] = 0array(
system powered-by -1 '#type' => 10'submit',
system help help '#value' => 0t('Submit'),
system navigation -1 0);
system management -1 return 0$form;
system user-menu -1 0}
system main-menu -1 0
user login -1 function edit_node_form_validate($form, &$form_state, 0$node){
user new if ($form_state['values']['node-1 0
user online id'] != $node-1 0>nid){
views hospitalist_scheduleform_set_error('node-block id', 'Node-1 0
views id hospitalist_on_call_today-blockmust match sidebar_seconda current 0nid.');
views admitting_hospitalist-block sidebar_second 0}
views -exp-all_assets-page -1
I see my block in the blocks list. But, my form is not showing up. I am wondering if I need to run a drupal_form_submit('edit_node_form', $form_state);
at the end, but shouldn't that be ran during a submit function?
I'm also wondering if I need to update the form_state as I'm not creating a form_id currently (eg https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_alter/7)
if (isset($form['type']) && $form['type']['#value'] . '_node_settings' == $form_id) 0{
views calendar-block_1 -1 $form['workflow']['upload_' . $form['type']['#value']] = 0array(
views calendar-block_2 -1 '#type' => 0'radios',
views -exp-form_view-page -1 '#title' => 0t('Attachments'),
devel execute_php '#default_value' => variable_get('upload_' . $form['type']['#value'], -1 0),
devel switch_user -1 0
'#options' custom_search_blocks=> array(t('Disabled'), 1t('Enabled')),
But I don't see my block, I have ran drush cc all multiple times, I have even went so far as to reboot my webserver to see ifthink that would catch it. But,is related to hook_form_alter which I still don't see the blockhave not called. tia