Creating a new select component

First up, we are going to add a new select listbox component to our form which will be used to indicate whether a particular submission has been previously flagged as declined.

How to do it...

To add a component to our form we need to be logged in to our site, navigate to our Speaker Registration form, and click on the Webform tab. By default, we should now see the Form components page.

  1. Scroll down to the textfield containing New component name and give the new component the name of Status.
  2. In the component type listbox we select Select options and click on Add.
  3. Enter the word Accepted as the Default value.
  4. In the Options textarea we specify our two status options as Accepted|Accepted on the first line and Declined|Declined on the next line.
  5. Scrolling down to the DISPLAY fieldset, we check the boxes at Listbox and at Private.
  6. Click on the POSITION fieldset heading to reveal the component positioning options.
  7. Select Root under Parent Fieldset.
  8. Enter -50 (minus fifty) under Weight.
  9. Click on Save component.
How to do it...

How it works...

We have now created a new listbox component to store the Status of each submission. The status can be either Accepted or Declined, with Accepted being the default value. This means that all the existing submissions that were completed prior to this component being added will appear as being Accepted when we edit them.

The new component will appear at the very top of the form as it has the lowest weight. Since we marked the component as Private, it will only be visible to those users who have at least Access all webform results permissions, and it will not be visible to any speakers who visit the Speaker Registration form.

This is the component whose value will decide whether or not our custom action will be shown when submissions are being viewed or edited. While the value of our Status component is Accepted or blank (as in the case of submissions already stored at the time that we created the new component), our administrators will be presented with the option to decline a submission.

There's more...

Adding this component has been the first step towards achieving the goals laid out for our action. Our next preparatory step is to obtain the component identifiers for the fields we will need to use in our action handler.

The data submitted via our form is stored as an array of values within a $submission object. To access the values submitted for particular components we need to know what the component identifier values are (the component identifier is a numeric value assigned to each component that we create on our form) for the respective components. Armed with the identifier we can access the $submission->data array to retrieve relevant submitted data.

The components whose values are pertinent to our action handler are those for speaker name, speaker surname, speaker e-mail address, presentation title, and most importantly, the status component we just added.

Determining component identifier values

Perhaps the easiest method of discovering component identifiers is by hovering our mouse pointer over the Edit link that appears under the heading of OPERATIONS on our component overview page.

Determining component identifier values

A portion of the URL (that is, hyperlink) contains the text webform/components/ followed by a number. That number is the component identifier for the component on that row. Let us make a note of the CIDs (component identifiers) for the five components we need: First name, Last name, Email address, Presentation title, and Status. Later in the exercise we will be able to use this information to interact meaningfully with the Webform $submission object to extract submitted data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset