Adding a markup component

Apart from the descriptive text that we may enter for specific components, we will occasionally want to insert a larger body of text, perhaps with a greater degree of HTML output formatting, as explanatory text on the body of the page. The markup component allows us to do just this.

How to do it...

  1. Let's create a new component named Page 2 Header text.
  2. Select Markup as the component type and click on Add.
  3. Enter the following HTML code into the Value textarea and click on Save component:
    <h4>Page 2 of 2</h4>
    <p>Please answer the survey questions below as <i>accurately</i> as you can.</p>
    

How it works...

HTML is an example of a Standard Generalized Markup Language (SGML) based language and is concerned, primarily, with expressing how information should be presented or laid out. In the preceding code, we have requested that the page number should be expressed in heading size 4 (the lower the number, the bigger the font size as an indication of importance) by enclosing it within the<h4> tags. The next sentence is defined as being part of a new paragraph by the<p> tags. The<i> tags that enclose the word accurately indicate to the web browser that it should display in italics.

Those of us unfamiliar with HTML would profit from the many HTML tutorials that abound on the Internet for further information on the myriad possibilities available. In most web browsers we may simply right-click on a web page and select View Source to see the HTML that defines how the web page information and presentation have been defined. While Webform is building our form components for rendering, we have the power now to inject extra presentation information for the convenience of our website visitors. We are welcome to add CSS classes to the HTML code in order to create the required presentation effect. The CSS styles for these additional classes may be added to our default theme CSS files.

How it works...

There's more...

Let us examine a few aspects of the markup component edit page in a little more detail.

Text format

While in the edit mode for a markup component, we see a drop-down list under the Value textarea where we may select the format rules for our input code. More information on text format can be gleaned by clicking on the More information about text formats link on this page. Visiting http://drupal.org/node/213156 on the Drupal website is a good place for us to explore the value and implications of these options.

PHP code

There is a PHP Filter module, which when enabled, allows administrators to insert PHP code into textareas on the site. This code will be executed while the corresponding page is being built.

This feature is a potential security risk!

We should not use this unless we absolutely have to. We should not give permission for this to anyone who is not a trusted user and who does not know both Drupal and PHP very well. A single typographical mistake in this PHP code can compromise the security and integrity of our entire website, as well as the underlying database.

At best, mistakes here can result in the dreaded WSOD (White Screen Of Death) which indicates that our web server was unable to complete processing and render our web page. In the worst case, we could unintentionally reveal important security information regarding our site and installation details.

It is far better, not to mention safer, to put together a standalone module to implement required functionality than to make use of the PHP code option.

By default, the module is disabled as this feature is being phased out of Drupal altogether. This permission is initially only available to the main site administrator. Let's keep it that way safety first!

The security implications are definitely non-trivial.

Token values

The markup component enjoys support for a wide range of token values, thus adding a dynamic complexion to the markup we enter here.

Conditional rules

A new fieldset has become available to us on the component edit page. When we insert page breaks in our forms, Webform gives us the ability to specify rules that will determine whether a component is actually displayed on subsequent pages or not.

The trigger fires based on the value of a component from one of the earlier pages in our form. We have the option to fire the trigger under one of two conditions:

  • The selected component contains a value included in the list under Values (that is, Is one of)
  • The selected component contains a value not included in the list under Values (that is, Is not one of)

For example, should we select the component Title and Is one of from the drop-down lists and enter Mr under Values, then this markup will display for all registering speakers who are your garden variety Mr. A registering user who selected a different title on the previous page, such as Dr, or Mrs, would not get to see this markup content at all.

Conditional rules

This powerful feature permits us, to a large extent, to create dynamic forms based on user input. For example, by making all of the components on a particular subpage conditional based on the same component from a preceding subpage, Webform may skip showing that page altogether. All of the fields on such a page will be blank in the database.

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

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