Closed (fixed)
Project:
Webform
Version:
6.x-3.2
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
20 Sep 2010 at 20:23 UTC
Updated:
4 May 2013 at 01:23 UTC
Since the webform module checks to prevent the use of duplicate component fieldnames, it would be nice if there were a built-in lookup function as part of the API
// **BEFORE**
function hook_webform_submission_presave($node, &$submission) {
// Update some component's value before it is saved.
$component_id = 4;
$submission->data[$component_id]['value'][0] = 'foo';
}
// **AFTER**
function hook_webform_submission_presave($node, &$submission) {
// Update some component's value before it is saved.
$component_id = webform_get_cid_from_fieldname($nid, 'customer_email');
$submission->data[$component_id]['value'][0] = 'foo@drupal.org';
}
The benefit here is that it is easy to remember the fieldnames you used when you created the webform,
but it is not always easy to remember or keep track of cid values.
Comments
Comment #1
quicksketchForm keys are not actually unique in Webform. They are merely uniquer *per-fieldset*. This makes it so you can have a fieldset for "billing" and a fieldset for "shipping" for example, with "address", "street", etc. underneath each one.
So the proposed method probably wouldn't work, it would need to be a look-up based on the parent-tree, such as
webform_get_cid_by_parents($node, array('billing', 'address'));. That said, I'm not sure a function is really necessary, it could also just be an array map, such as$node->webform['map']['billing']['address']to get you the CID.Comment #2
stephen.moz commentedThanks for the reply.
Comment #3
stephen.moz commentedclose