I think you should add the feature where when a user submits a webform using the webform module, you can make them to get points.

Comments

trevorleenc’s picture

this would be a great feature, so if you had a site survey or something, you could award points when someone completes the survey...just one example I'm sure.

kbahey’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Status: Active » Postponed (maintainer needs more info)

The clean way to do this is to write a new module that integrates userpoints with Webform. It would implement a hook_someting that webform implements and act accordingly.

If webform does not have such a hook, then doing a form_alter on the specific form and adding a submit handler that would call userpoints from there and add the points specified.

If someone writes such a module, please post an issue for userpoints_contrib and attach your module and info file.

boran’s picture

Here is some test code that seems to work for me.
Webform does not seem to have any usable hooks, so hook_form_alter was used.

function mymodule_form_alter($form, $form_state, $form_id){

  // catch webform submits, award points
  $form['#submit'][] = 'mymodule_form_submit';
}

function userpoints_visits_form_submit($form, $form_state) {
  //dsm($form_state);
  // is this a Submit for a Webform?
  if ( (strlen($form_state['values']['op']) > 0)
    && (strpos($form_state['values']['form_id'], 'webform_client_form_') === 0) ) {

    $formid=str_replace('webform_client_form_', '', $form_state['values']['form_id']);
    __debug1("_form_submit: webform action: " .  $form_state['values']['op'] .", form id $formid", 2);

    $points=variable_get(USERPOINTS_VISITS_WEBFORM, 0);
    if ($points > 0) {
      $reason='Survey completed';
      userpoints_userpointsapi(array(
        'uid'         => $user->uid,
        'points'      => $points,
        'operation'   => 'answer',
        'description' => $reason,
        'entity_id'   => $formid,
        'entity_type' => 'webform',
        'tid'         => variable_get(USERPOINTS_VISITS_TID, 0),
      ));
      __debug1("_form_alter: $reason, awarded $points on webform $formid", 1);
    }

}

And a bit of code to define MYMODULE_ settings and read in value on admin/settings/userpoints.
A module just for that seems a bit over the top, would be better to integrate into an existing module?

gausarts’s picture

Jut a note: http://drupal.org/node/438688

Much simpler :)

Bilmar’s picture

Status: Postponed (maintainer needs more info) » Fixed

Marking this fixed as solution was shared in http://drupal.org/node/438688 and mil1ion confirmed.

Also, this should be possible with Rules Forms support sub-module within Rules. Enable the form to be used with Rules, then set the rules event, conditions, actions.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.