Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I've this hook that gets submitted values from my form which as 2 select options elements and prints the 2 values submitted.

function modsubmit_webform_submission_insert($node, $submission)
{
$cont=0;
foreach($submission->data as $val) {
      $value = array_shift($submission->data);
        $value = array_shift($value['value']);
        $data[$cont] = $value;
        $cont=$cont+1;}

drupal_set_message("The value inserted was: {$data[0]},{data[1]}"); }

Now i want to use this two values to make a sql query in db, and the result showed in a table. I can't get this to work, solutions needed

Thanks

share|improve this question

1 Answer

If you want to alter how a submission is rendered, for example adding a table, you need to implement hook_webform_submission_render_alter(). The hook receive the data for the submission in $renderable['#submission'], and the node in $renderable['#node'].

An example of hook_webform_submission_render_alter() is webform_webform_submission_render_alter(), which contains the following code.

function webform_webform_submission_render_alter(&$renderable) {
  // If displaying a submission to end-users who are viewing their own
  // submissions (and not through an e-mail), do not show hidden values.
  // This needs to be implemented at the level of the entire submission, since
  // individual components do not get contextual information about where they
  // are being displayed.
  $node = $renderable['#node'];
  $is_admin = webform_results_access($node);
  if (empty($renderable['#email']) && !$is_admin) {
    // Find and hide the display of all hidden components.
    foreach ($node->webform['components'] as $cid => $component) {
      if ($component['type'] == 'hidden') {
        $parents = webform_component_parent_keys($node, $component);
        $element = &$renderable;
        foreach ($parents as $pid) {
          $element = &$element[$pid];
        }
        $element['#access'] = FALSE;
      }
    }
  }
}

The purpose of hook_webform_submission_insert() is inserting the submitted data in a database. You can use that hook to save the data in a database, and show those data in a page rendered from your module, but hook_webform_submission_insert() is not thought to render any data.
To make a paragon, hook_webform_submission_insert() is equivalent to hook_node_insert() that is invoked when a new node is saved, but that should not render any page.

share|improve this answer
 
this function modsubmit_webform_submission_render_alter(&$renderable) { $node = $renderable['#node']; drupal_set_message(t('Saved @title.',$node)); } isn't print anything. –  Peninha Nov 27 '12 at 10:06
 
Are you editing an enabled module? If that is the case, Drupal caches the hooks implemented from the modules, and it doesn't notice a module has been modified, if the module is not first disabled, and then re-enabled. hook__webform_submission_render_alter() is the hook you should use if you want to alter how a submission is rendered. –  kiamlaluno Nov 27 '12 at 13:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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