Converting a set of pages into using formtemplate

This page show how to convert a set of pages that doesn't use formtemplate into using formtemplate

  1. Let's take this simple form (let's say it's called form.adp) :
    <form method="post" name="news" action="item-create-2">
    	<table>
    	<tr>
    		<td>Title</td>
    		<td><input type="text" size="51" maxlength="400" id="publish_title" name=publish_title value="@publish_title@"></td>
    	</tr>
    
    	<tr>
    		<td>Lead</td>
    		<td><textarea id="publish_lead" name=publish_lead cols=50 rows=3>@publish_lead@</textarea></td>
    	</tr>
    
    	<tr>
    		<td>Body *</td>
    		<td><textarea id="publish_body" name=publish_body cols=50 rows=20  wrap=soft>@publish_body@</textarea></td>
    	</tr>
    
    	<tr>
    		<td></td>
    		<td align="left"><input type="submit" value="Submit"></td>
    	</tr>
    </form>
    
  2. Now what's wrong with this form? NOTHING! Then why do we need to switch to using formtemplate? Because formtemplate offers us several advantages.
  3. Let's examine how to use ad_form.
  4. Using formtemplate consists of two main components:
    • The <formtemplate> tag in the adp page
    • The ad_form procedure
  5. To replicate the above form using formtemplate, we do the following:
    • Modify/create form.tcl and use ad_form to define the widgets using ad_form
    • To replicate the above form, the call to ad_form would look like:
    • ad_form -name news -method post -form {
      	{story_id:key(acs_object_id_seq)}
      	{publish_title
      publish_lead
      publish_body
      submit:
      }	
      
    • Then modify the adp page (form.adp) and get rid of everything between <form> and &lgt;/form> including the form tags themselves.
    • Now add the following to form.adp:
      <formtemplate id="news"></formtemplate>
      
    • Voila, your initial form is now set up.
  6. Now we need to think about submitting to the database.
  7. For files that don't use ad_form, the form usually submits to a different page.
    Using formtemplate eliminates this. Most pages that use formtemplate will just submit back to the same page. One of the main advantages of submitting back to the same page is that you can get inline error messages in the form.