2

I am trying to display results of a certain content type (webform: event)

So my idea is that i would embed the table into the the tpl (node--event.tpl.php) I tried many different ways and the closest i can get is the following code

module_load_include('inc','webform','includes/webform.submissions');
$submissions = webform_get_submissions(array('nid'=> 4));

foreach ($submissions as $submission){
    foreach ($submission->data as $row=>$data){
        print '<pre>';print_r($row);print '</pre>';
        print '<pre>';print_r($data);print '</pre>';
    }
}

This works but just for a single node, in this case node 4, I would like to show this of the current node.

0

Try the Webform Report module, it looks perfect for what you need.

Or, Why not use views?

It would be easier to use webform 7.x-4.0-rc3 and create a view table for webform submission data. You can easily grab the separate values and arrange them into a table.

You also have the ability to create a reference so only the results from node 4 are being shown.

EDIT: use $node->nid; , so...

$nid = $node->nid;

module_load_include('inc','webform','includes/webform.submissions');
$submissions = webform_get_submissions(array('nid'=> $nid));

foreach ($submissions as $submission){
    foreach ($submission->data as $row=>$data){
        print '<pre>';print_r($row);print '</pre>';
        print '<pre>';print_r($data);print '</pre>';
    }
}
  • The result has to be that there is a submission data tabel(Ex. the name and birth date of everyone who has signed up for the current event) on each eventpage. How can I do that in views? Or is this added in 7.x-4.0? – Jobse May 1 '14 at 13:41
  • Create new view, change content to "webform submission data", click use fields, then click save. Webform submission data will now be available in "add field" as "webform-submission:data". Then just choose which field you want to use, e.g. name, or birth date. – Collins May 1 '14 at 14:27
  • But then you need to make a block for every event, it should show all fields except a few (but thats probably css) on every event – Jobse May 1 '14 at 14:34
  • I would just create a contextual filter on the view of "get content from url". In the block configuration, make it appear on all of your nodes of that content type. Then set the permissions of that block so only admin can see them. That way, an admin can easily navigate to an event sign up page, and get a quick and easy submissions table. – Collins May 1 '14 at 14:45
  • I expect you mean by [Webform submission data: Value] But you need to enter manually a nid so how can a contextual filter fix that? – Jobse May 1 '14 at 14:48
0

I guess this is gonna hurt a lot of eyes but it works perfect for my case.

This is not the way I am suppose to work in drupal so if anyone can (help me) convert this to a hook or small module, i would love that.

I added the following code to my node--event.tpl.php to show a table of all results for the current node without a few unwanted results like e-mail.

        // Create connection
        $con=mysqli_connect("******","*******","********","*********");

        // Check connection
        if (mysqli_connect_errno()) {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        // Get submitted data from current nodeform
        $result = mysqli_query($con,"SELECT data, cid, sid, nid FROM webform_submitted_data WHERE nid=".$nid);
        $data = array();
        $i =0;
        while($row = mysqli_fetch_array($result)) {
          $data[$i]['data'] = $row['data'];
          $data[$i]['sid'] = $row['sid'];
          $data[$i]['cid'] = $row['cid'];
          $data[$i]['nid'] = $row['nid'];
          $i++;
        }
        // Get headers for submitted data
        $result = mysqli_query($con,"SELECT name, form_key, cid FROM webform_component WHERE nid=".$nid);
        $headers = array();
        while($row = mysqli_fetch_array($result)) {
          $headers[$row['cid']]['name'] = $row['name'];
          $headers[$row['cid']]['form_key'] = $row['form_key'];
        }


        // Declare variables for composing table
            //unwanted fields
            $unwanted[] = 'productid';
            $unwanted[] = 'e_mail';
            $unwanted[] = 'algemene_voorwaarden';
        $newCello = '<td>';
        $newCellc = '</td>';
        $presid = (isset($data[0]['sid'])) ? $data[0]['sid'] : '' ;
        $tablehead = '<tr class="head">';
        $tabledata ='<tr>';
        $even = TRUE;
        //render table
        foreach ($data as $key) {
            if ($key['sid'] != $presid) {
                $tabledata .= "</tr>";
                $tabledata .= ($even) ? '<tr class="even">' : '<tr>' ;
                $firstrow = TRUE;
                $even = ($even) ? FALSE : TRUE ;
            }
            //filter unwanted fields
            $formkey = $headers[$key['cid']]['form_key'];
            if (!in_array($formkey, $unwanted)) {
                //create table headers
                if (!isset($firstrow)) {
                    $tablehead .= $newCello;
                    $tablehead .= $headers[$key['cid']]['name'];
                    $tablehead .= $newCellc;
                }
                $tabledata .= $newCello;
                $tabledata .= $key['data'];
                $tabledata .= $newCellc;

                //Get current field sid to compare with the next
                $presid = $key['sid'];
            }
        }

        $tablehead .= '</tr>';
        echo $tablehead;
        echo $tabledata;
        mysqli_close($con);
        ?> 
        </tr>
    </tbody>
</table>

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.