1

So i have created a page which uses an XML feed to generate some output. I want to be able to add a textarea from the FORM API so that i can allow user of my site to enter some details on to the form itself.

Similar functionality to how entityform works, seemed like a simple task, but not sure how to do it.

  • Take a look at drupal.org/project/admin_notes – Gokul N K Jun 25 '14 at 6:15
  • OK thanks for your answer, for something that should be an easy functionality was kind of an issue. Managed to find some information on how to do it using a block. – Key Jun 25 '14 at 10:42
0

OK thought i would answer my own question and show the method in which this is done. First declare a block, with a block view and then define a custom callback function that defines the textarea, are any output from Drupal's Form API.

function hook_block_info() {
  $blocks['box_question'] = array(
    'info' => t('Box question area'),
  );
  return $blocks;
}

function hook_block_view($delta = '') {
  $block['subject'] = t('TEST');
  $block['content'] .= drupal_render(drupal_get_form('custom_block_form'));
  return $block;
}

function custom_block_form($form, &$form_state) {
  $form['question'] = array(
    '#markup' => 'this is a block,
  );
  $form['answer'] = array(
    '#type' => 'textarea',
    '#resizable' => FALSE,
    '#default_value' => $default,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#name' => 'save',
    '#attributes' => array(
      'class' => array('save-button'),
    ),
  );
  return $form;
}

The custom_block_form is what defines the form blocks, call the submit functions to make your own callback on what to do when the form is saved.

|improve this answer|||||

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.