When a link is clicked, a value is retrieved from the table and displayed on a Webform field I have created a basic page with two buttons, "Yes" and "No". When the "Yes" button is clicked, it is directed to the webform.

Aim: When the webform appears, it displays a value from the table into a field. 

Database


Table name: Room
Field: Room
Data: Training Room


The Basic Page



The Webform



I created a module for this functionality:

test_presave.info

name = "Test presave"

description = "Retrieving data from table"

core = 7.x

package = Test


test_presave.module

/*

*Implements hook_node_presave()

*/

function test_presave_node_presave($node)

{

    $accessnode=$node-&gt;nid;

    if($accessnode==20)//Lettable Room Booking webform

    {

        $result=$db_query("SELECT Room FROM {Room} WHERE Room =:ln",array(':ln'=&gt;'Training Room'))-&gt;fetchCol();

        $node-&gt;webform['components'][1]['value']=$result;

    }

}   


Am I using the correct hook? 

Do I have to use the node api or the webform api? 

Can you help me with this?
Rather do this:

Alter the button link to include a parameter:

&lt;a href="./lettable-room-booking?captured=true"&gt;Yes&lt;/a&gt;


In hook_form_alter, check for the parameter and set the default value(s):

function test_presave_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    // dpm($form_id); // uncomment to get $form_id
    // dpm($form); // uncomment to get $form
    if ($form_id == 'webform_client_form_2') { // use dpm($form_id) to get your form id
        $param = drupal_get_query_parameters();
        if (isset($param['captured']) &amp;&amp; $param['captured'] == "true")
        {
            $result = ...
            if ($result) {
                $form['submitted']['room']['#default_value'] = $result; // use dpm($form) to get your room field
            }
        }
    }
}