I built a questionnaire on Survey Monkey and had 75 people fill it in. I now need people to repeat the same questionnaire (which I am rebuilding in Webform) BUT I have to show the option they previously selected and the average across the entire survey.

I have all previous answers in a mysql database, so what I would like to do is to drop the user-specific answers in.

i.e. Last time you answered ....

Is there any way to get Webform to do this (i.e. with the Markup feature possibly?) or is this beyond its remit? I have people who are willing to help me with this, but wanted to see whether the Drupal community had any ideas first.


Perhaps I can give you an example. Say for the first round of the questionnaire you ask people:

How do you feel about cats? 1) Love them 2) Like them 3) Dislike them 4) Hate them.

A week later, you then ask people to repeat that same question, except the question looks like this.

How do you feel about cats?

Last time you selected 'Love them'

In the survey overall people made the following choices: 1) Love them 25% 2) Like them 40% 3) Dislike them 25% 4) Hate them 10%

Please now re-answer.

1) Love them 2) Like them 3) Dislike them 4) Hate them

Thanks for your help. I hope this is a bit clearer!

1 Answer 1


Your question is not completely clear, but as I understand you want to load a custom set of dropdown options as a webform element.

You can do that from a custom module with the following example code:

 * Implements hook_webform_select_options_info().
 * Defines a custom dropdown form element to be used with the Webform module.
function YOURMODULE_webform_select_options_info() {
  $items['last_time_answered'] = array(
    'title' => t('Last time you answered'),
    'options callback' => '_YOURMODULE_get_options',
  return $items;

 * Generate "Last time answered" options for the current user.
 * Used for sample webform element.
function _YOURMODULE_get_options() {
  // Your query goes here
  // Return should be an array with $value => $label structure.
  return array(
    1 => 'Option 1',
    2 => 'Option 2',
    3 => 'Option 3',

I also suggest to drop in a custom validator to the webform:

 * Implements hook_form_alter().
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {
    // Sample webform custom validation
    case 'webform_client_form_1':
      $form['#validate'][] = '_YOURMODULE_validate_custom_field';
      $first = array_shift($form['#submit']);
      array_unshift($form['#submit'], $first, '_YOURMODULE_validate_custom_field');


 * Custom validation function for webform component.
function _YOURMODULE_validate_custom_field() {
  foreach ($form['#node']->webform['components'] as $element_id => $element) {

    if ($element['form_key'] == 'last_time_answered') {

      // Perform the check here
      if ($element['value'] != 'Sample value') {
        form_set_error('', t('Validation message.'));



To use this custom field, create a new webform element (select options) and choose your new list from the "Load a pre-built option list" dropdown.

  • Thanks for your reply. I have edited the original question to give a, hopefully, better example.
    – Ed O'Meara
    Oct 17, 2012 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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