Skip to main content
edited code and updated question
Source Link

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

I'm trying to create a custom form displayed inside of a block.

Here is my code:

<?php
/*
 * Creating custom form to edit/delete nodes
 */
function custom_block_settings_form($form, &$form_state){
    $form['node-id'] = array(
        '#type' => 'textfield',
        '#title' => 'Node Number',
        '#maxlength' => 15,
        '#size' => 15,
        '#required' => TRUE,
    );
    $form['edit-delete'] = array(
        '#type' => 'radios',
        '#options' => array('edit' => 'Edit', 'delete' => 'Delete'),
        '#required' => TRUE,
    );
    $form['save'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
        '#submit' => array('custom_block_form_submit'),
        '#validate' => array('custom_block_form_validate'),
    );
    return $form;
}
/*
 * running validation on the form to verify node id is correct
 *
 */
 
function custom_block_settings_form_validate($form, &$form_state, &$node){
    if (($node->nid) != ($form_state['value']['node-id']));
        form_set_error('node-id', 'Please enter a valid node-id');
}
/*
 * Create block
 */
function custom_block_settings_block_info(){
    $blocks = array();
    $blocks['custom_block_settings'] = 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 =- array();
    switch ($delta) {
        case 'custom_block_delete':
        $block['subject'] = t('Custom Block');
        $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              0
 block                 2                                -1              0
 block                 3                                -1              0
 backup_migrate        quick_backup                     -1              0
 calendar              calendar_legend                  -1              0
 comment               recent                           -1              0
 context_ui            editor                           -1              0
 context_ui            devel                            -1              0
 fullcalendar_legend   fullcalendar_legend              -1              0
 logintoboggan         logintoboggan_logged_in          -1              0
 menu                  devel                            -1              0
 node                  syndicate                        -1              0
 node                  recent                           -1              0
 search                form                             -1              -1
 shortcut              shortcuts                        -1              0
 system                main                             content         0
 system                powered-by                       -1              10
 system                help                             help            0
 system                navigation                       -1              0
 system                management                       -1              0
 system                user-menu                        -1              0
 system                main-menu                        -1              0
 user                  login                            -1              0
 user                  new                              -1              0
 user                  online                           -1              0
 views                 hospitalist_schedule-block       -1              0
 views                 hospitalist_on_call_today-block  sidebar_second  0
 views                 admitting_hospitalist-block      sidebar_second  0
 views                 -exp-all_assets-page             -1              0
 views                 calendar-block_1                 -1              0
 views                 calendar-block_2                 -1              0
 views                 -exp-form_view-page              -1              0
 devel                 execute_php                      -1              0
 devel                 switch_user                      -1              0
 custom_search_blocks  1

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 if that would catch it. But, I still don't see the block. tia

I'm trying to create a custom form displayed inside of a block. [edited]

 <?php  

function edit_node_block_info(){
    $blocks['edit_node'] = array(
        'info' => t('Custom Block to allow edit/delete/copy'),
        'status' => 1,
        'region' => 'Primary',
        'weight' => 0,
        'visibility' => BLOCK_VISIBILITY_LISTED,
    ); 

    return $blocks;
}
/*
 * Implements hook_block_view: sets how the block is displayed
 */
function edit_node_block_view($delta = ''){
    switch ($delta) {
        case 'edit_node' :
            $block['subject'] = t('Edit Nodes');
            $block['content'] = drupal_get_form('edit_node_form');
            break;
    }
    return $block;
}
/*
 * implements custom form/creating custom form for drupal_get_form named above.
 */

function edit_node_form($form, &$form_state) {
    $form['node-id'] = array(
        '#type' => 'textfield',
        '#title' => t('Enter the Node ID'),
        '#max-length' => 8,
        '#required' => TRUE,
    );
    $form['edit-node'] = array(
        '#type' => 'radios',
        '#title' => t('Select Action'),
        '#options' => array(t('edit'), t('delete'), t('copy')),
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
    );
    return $form;
}

function edit_node_form_validate($form, &$form_state, $node){
    if ($form_state['values']['node-id'] != $node->nid){
        form_set_error('node-id', 'Node-id must match a current nid.');
    }

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) {
    $form['workflow']['upload_' . $form['type']['#value']] = array(
      '#type' => 'radios',
      '#title' => t('Attachments'),
      '#default_value' => variable_get('upload_' . $form['type']['#value'], 1),
      '#options' => array(t('Disabled'), t('Enabled')),

But I think that is related to hook_form_alter which I have not called.

edited tags
Link
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91
Source Link

Custom Form Block not displaying

I'm trying to create a custom form displayed inside of a block.

Here is my code:

<?php
/*
 * Creating custom form to edit/delete nodes
 */
function custom_block_settings_form($form, &$form_state){
    $form['node-id'] = array(
        '#type' => 'textfield',
        '#title' => 'Node Number',
        '#maxlength' => 15,
        '#size' => 15,
        '#required' => TRUE,
    );
    $form['edit-delete'] = array(
        '#type' => 'radios',
        '#options' => array('edit' => 'Edit', 'delete' => 'Delete'),
        '#required' => TRUE,
    );
    $form['save'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
        '#submit' => array('custom_block_form_submit'),
        '#validate' => array('custom_block_form_validate'),
    );
    return $form;
}
/*
 * running validation on the form to verify node id is correct
 *
 */

function custom_block_settings_form_validate($form, &$form_state, &$node){
    if (($node->nid) != ($form_state['value']['node-id']));
        form_set_error('node-id', 'Please enter a valid node-id');
}
/*
 * Create block
 */
function custom_block_settings_block_info(){
    $blocks = array();
    $blocks['custom_block_settings'] = 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 =- array();
    switch ($delta) {
        case 'custom_block_delete':
        $block['subject'] = t('Custom Block');
        $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              0
 block                 2                                -1              0
 block                 3                                -1              0
 backup_migrate        quick_backup                     -1              0
 calendar              calendar_legend                  -1              0
 comment               recent                           -1              0
 context_ui            editor                           -1              0
 context_ui            devel                            -1              0
 fullcalendar_legend   fullcalendar_legend              -1              0
 logintoboggan         logintoboggan_logged_in          -1              0
 menu                  devel                            -1              0
 node                  syndicate                        -1              0
 node                  recent                           -1              0
 search                form                             -1              -1
 shortcut              shortcuts                        -1              0
 system                main                             content         0
 system                powered-by                       -1              10
 system                help                             help            0
 system                navigation                       -1              0
 system                management                       -1              0
 system                user-menu                        -1              0
 system                main-menu                        -1              0
 user                  login                            -1              0
 user                  new                              -1              0
 user                  online                           -1              0
 views                 hospitalist_schedule-block       -1              0
 views                 hospitalist_on_call_today-block  sidebar_second  0
 views                 admitting_hospitalist-block      sidebar_second  0
 views                 -exp-all_assets-page             -1              0
 views                 calendar-block_1                 -1              0
 views                 calendar-block_2                 -1              0
 views                 -exp-form_view-page              -1              0
 devel                 execute_php                      -1              0
 devel                 switch_user                      -1              0
 custom_search_blocks  1

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 if that would catch it. But, I still don't see the block. tia