Creating a blank form for adding new records to a database
Sometimes you want a form to appear blank even though it has fields bound to a content source. This is usually because the form will be used for entering new data that is to be added to a database table. There are several ways of making a form with bound elements blank. The technique to use depends on the interaction flow of your Web site. Some of these techniques depend on the flow of pages displayed in the site. The following descriptions refer to the page with the form that is to be blank as the current page and the page that was displayed immediately before as the previous page. - If the page is displayed as a result of following a link from a page displaying records from the same content source, you can add a Link Action Show Details of Empty Record to the link. This will add a special URL parameter to the link that causes the content source on the current page to return no results, making the form (and anything else bound to that content source) blank. The content source must have the same name on the previous and current pages. This technique will cause both form actions Update Record and Add Record to add a new record.
- If the page is displayed as a result of pressing a form button on a previous page and the previous page is showing records from the same table, you can use the Clear Form Data form action. Like the Show Details of Empty Record form action, this will add a special URL parameter that causes the content source to return no results. The content source must have the same name on the previous and current pages. This technique will cause both form actions Update Record and Add Record to add a new record.
- If the preceding techniques cannot be used (possibly because the interaction flow in the site does not make it easy to determine all previous pages), you can change the content source itself so that it returns no records. To do this, add a content source filter that will never be true. For example, if the record has an Id field, you can add a test for Id = -1 which will never be true assuming Ids are assigned starting at 1.
- You can also make a form blank by placing a piece of custom code on the page in front of the form. In ASP, insert the code <%MoveToEnd(content_source_name)%>; for JSP, insert the code <% gl.moveToEnd(content_source_name) %>; and for PHP, insert the code <?php MoveToEnd($content_source_name)?>. Each of these pieces of code positions the content source at the end of its list of records so that no more records will be returned. Since the form follows the code, the bindings in the form will find no data in the content source.
|