0

How can I fetch list of published webforms from webform module?

I want to show all published webforms in dropdown to the user, so user can select one of the available forms.

Cheers -Zafar

  • you can use views, currently dont have enough time to explain, but if u couldn't figure it out, I will explain it to you in an hour – Sohail Feb 2 '14 at 16:15
  • I need a dropdown with listing published webforms in FORM(hook_form),views would be good idea for only showing/listing webforms seperately. – Zafar S Feb 2 '14 at 17:05
  • I need a query to fetch all published webforms from database. – Zafar S Feb 2 '14 at 17:06
3

In Drupal 7 it would be something like:

$nodes = node_load_multiple(array(), array(
  'type' => 'webform',
  'status' => 1,
));

Have a look at the docs for node_load_multiple. You could (and probably should) also use EntityFieldQuery as mentioned in the docs. The given examples assumes that you use the default webform content type.

You could then use the $nodes array to build options for a Form API select element:

$webforms = array();
foreach ($nodes as $nid => $node) {
  $webforms[$nid] = check_plain($node->title);
}
$form['available_webforms'] = array(
  '#type' => 'select',
  '#title' => t('Webforms'),
  '#options => $webforms,
);
| 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.