3 Oct 2012
Remark: This is a clumsy way to add a component, as the component is integrated into WebForm's source. You can actually build an independent module that utitlizes WebForm's hooks in order to build a component.
Today I've successfully added a component (e.g. textbox) to WebForm module of Drupal.
I cannot write about what it is, but I can say how I've built it (I guess). I am pretty new with the hightech workplace and stuffs. I've gotta be careful. Well, it's just a Drupal knowledge anyway.
So, here it is:
file under ``webform/components
`. You may just make a copy of
in ``webform/webform.module```. (There are several examples in that function)
Please note that all functions in your
must be in the form of ``_webform_somehook_yourcomponentname()```.
`webform/webform.api.php` for more description.
The thing to understand is that Drupal has its own element generator (outside WebForm).
You can do download examples and look into
`form_examples`. It's really helpful.
The problem that I've encountered is that I generate a
`markup` element that has a div inside.
That is because when I generate the element, I didn't tell Drupal that this element would have a value being submitted from a user.
So, Drupal can be told with:
$element = array( '#type' => 'markup', '#input' => TRUE, // this line '#return_value' => TRUE, // and this line '#markup' => '<div style="display: none;">' . json_encode($data) . '</div>', );
When you generate a
`markup` element, you must leave a clue like this:
$element = array( '#type' => 'markup', '#input' => TRUE, // this line '#return_value' => TRUE, // and this line '#markup' => '<div class="some-weird-named-class" style="display: none;">' . json_encode($data) . '</div>', );
`webform/js/webform.js`. Here is how I added the code: