In this How To you will learn how to use the form creation features in KTML to build a basic contact form. The page you will build within the KTML editor will allow a visitor enter a name, e-mail and message in text fields, select the region of residence with a drop-down menu and pick a comment type using a radio group. The page will then submit to a page that sends all of the information by e-mail to a predefined address.
To follow this tutorial you need:
A page that displays content edited with KTML.
A page that uses the KTML editor as replacement for a text area. Learn how to create such a page here.
The e-mail sending script.
A web server running an application server where to place the files above.
This simple application uses three pages:
index - this page displays content created with KTML.
edit - this page contains an instance of the KTML editor.
send_mail - simple e-mail sending script.
To create these files quickly, you can use the files provided in the downloaded package in the tutorials\how_to_s\contact_form folder specific for your particular server model.
The contact form will be created completely in KTML, and will contain the following elements:
The Name field set which will contain two text fields: First name and Last name.
A drop-down menu which allows selecting the region of origin. Its options are static: Western Europe, Central Europe, Eastern Europe, North America, South-East Asia, Other.
A text field to insert the sender's e-mail address
A radio group to select the comment type, with three (3) choices: Suggestion/Question/Complaint.
A text area where the user will enter its comments.
The form will submit to the send_mail page in the same folder. The field names will be explained later on, when each of them is created.
To create the form you have to:
In the second table cell type Last name, then press Shift+Enter/Return to create a line break. Then, from the Forms toolbar insert a text field:
In the Text Field Property Inspector that is displayed when inserting the second field change the Name to lastName:
Click below the fieldset to continue adding fields. Next is the drop-down with the regions. Create a new line below the fieldset and type: Region where you live. Press Shift+Enter to create a new line break afterwards.
Note: Make sure you are still within the form's red dotted border.
From the Forms toolbar add a drop-down menu.
In the List/Menu Property Inspector, in the Name text field enter region. Then press the List Values button to add items to the menu:
In the List / Menu Options Editor window you can define the menu items, as pairs of labels and values. To add a new item:
Click the Plus(+) button. The Item label and Item value text fields will be enabled.
In the Item label text field enter the text to be displayed in the menu. For the first entry type Western Europe.
In the Item value text field enter what the menu will pass to the processing page for the selected entry. For this sample you will use the same text as for the label: Western Europe.
Note: As you enter the value, it is copied in the menu items list.
Repeat the actions in step 17 to add some more items to the menu. Use the following for both label and value: Central Europe, Eastern Europe, North America, South-East Asia, Other. The completed menu structure is:
Click OK to close the interface and return in the KTML editable area. Press Enter/Return to create a new paragraph after the drop-down menu. For the label enter E-mail address. Then press Shift+Enter to create a new line break.
From the Forms toolbar add a new text field. In the Text Field Property Inspector set its name to emailAddress.
Place the mouse cursor after the e-mail text field and press Enter/Return to create a new paragraph. Type Type of comment, and create a new line break. The user will be able to select one of the possible comment types - suggestion, question, complaint - using a radio group. To create the radio group you have to add each radio button at a time, using the same name for all of them. From the Forms toolbar, click the Radio Button icon:
In the Radio Button Property Inspector that is displayed enter in the Name field commentType. This name will be used for all three radio buttons. In the Value text field enter the value passed by the button to the processing page. For this sample you will use the label as value.
Place the mouse cursor next to the radio button and enter the label - Suggestion:
Repeat steps 21-23 and add two more radio buttons. Use the same name, but for the value and label use the remaining options: question and complaint:
Next create a new paragraph for the comment textarea. First enter the label - Comment, then create a new line break. From the Forms toolbar add a Text Area element by clicking on its icon:
In the Name field of the Property Inspector enter comment.
Create a new paragraph after the text area and add a submit button from the Forms toolbar:
Configure the button using the Property Inspector displayed when selecting the button:
In the Name field enter submit.
In the Label field enter Send e-mail.
In the Action area select the Submit form radio button.
With this last element the contact form is completed, and you can test it. If you used any other names for the fields you have to edit the e-mail sending script and replace the default ones with your particular values. To save the form, click the submit button on the edit page. The form will be displayed on the index:
The send_mail file contains a simple script that reads the form field content - for the field names specified in the code above - and sends a message to an address you must configure. The line that defines the e-mail address is on top of the file, and by default uses the nobody@nobody.com address. Replace this with the address you want to receive messages on - e.g. contact@domain.org:
Note: The code line above is for the ASP.Net version of the script. For other version the syntax is different.
If using ASP.Net you must check that no other form - e.g. the default form added by Visual Studio for web form pages - exist on page. If it does, remove it to get the e-mail functionality.
If you fill in the form and click the Send e-mail button, a message will be delivered containing all fields from the form: