1

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.

  • I just got it working by changing the page's it was viewable on. Not really sure why that fixed the issue, but it did. – sdudenhofer Jan 13 '16 at 18:58
0

I just got it working by changing the page's it was viewable on. Not really sure why that fixed the issue, but it did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.