Quick links: Content - sections - sub sections
EN

Trace: jelixnews-1.7 1.4 1.3.x 1.2.x faq

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:tutorials:main:news-form [2007/09/16 06:52] – created laurenten:tutorials:main:news-form [2008/11/19 21:43] (current) laurent
Line 1: Line 1:
-====== Creation of a news form ======+form system, jForms, is available in Jelix, but we will see it in a next chapter.
  
-A form systemjForms, is under development and will be available in Jelix 1.0 beta2. jForms deals with received data from forms server side and client side at the same time (HTML, XUL, or web services) : creation, save, data check, etc. +For the momentwe're going to see how to deal with forms in a "traditionnalway. We will to create a form in order to record some new news.
-This part is more or less operational in Jelix 1.0 beta1 but remains however experimental. jForms will be also handle the generation of HTML, XUL or other forms in the templates (starting from jelix 1.0 beta2). +
- +
-While waiting, you will have to use more "traditionalmethod :-)  +
- +
-The goal of this chapter, will be to create a form in order to record some new news.+
  
  
Line 16: Line 11:
 <h1>Creation of a news</h1> <h1>Creation of a news</h1>
  
-<form action="{jurl 'news~default_createsave'}" method="POST"/>+<form action="{formurl 'news~default:createsave'}" method="POST"> 
 +{formurlparam 'news~default:createsave'}
 <table> <table>
 <tr> <tr>
Line 31: Line 27:
 </tr> </tr>
 </table> </table>
-<p><input type="submit" value="Save"/></p>+<p><input type="submit" value="Save"/
 +<a href="{jurl 'news~default:index'}">Cancel</a></p>
 </form> </form>
 </code> </code>
-Very classical, put aside the template tag {jurl}. In Jelix, you will avoid putting urls directly in the templates or the actions, for ease of maintenance and evolution reasons. The URL system of Jelix enables you to centralize all the urls in the jelix config or a urls.xml file (all depends on the URL engine used). The jUrl object and the tag {jurl} enable you to obtain a URL by giving only the name of the action and eventually the parameters.  
  
-Here then, we state that the form will be submitted to URL of the default_createsave action.+Very classical, put aside the template tags {formurl}, {formurlparam} and {jurl}.  
 + 
 +In Jelix, you will avoid putting urls directly in the templates or the actions, for ease of maintenance and evolution reasons. The URL system of Jelix enables you to centralize all the urls in the jelix config or a urls.xml file (all depends on the URL engine used). The jUrl object and the tag {jurl} enable you to obtain a URL by giving only the name of the action and eventually the parameters.  
 + 
 +We could have used the tag {jurl} also in <form> tag, but if the URL contains parameters (as is the case here with module and action), it is best to put them in hidden fields. However, if we changed the configuration on the mapping url, it is not forced there is always these parameters. Also being used in conjunction plugins {formurl} and {formurlparam} who will themselves decide what to put in the attribute "action", and what should be put in hidden fields. 
 + 
 +Here then, we state that the form will be submitted to URL of the default:createsave action.
  
-Note: by default, {jurl} correctly escapes the reserved characters in HTML/XML.+Note: by default, {jurl}, {formurl} and {formurlparam} correctly escapes the reserved characters in HTML/XML.
  
  
Line 58: Line 60:
  
 <code> <code>
-    <p><a href="{jurl 'news~default_createform'}">Add a news</a></p>+    <p><a href="{jurl 'news~default:createform'}">Add a news</a></p>
 </code> </code>
  
Line 65: Line 67:
 ===== Saving the data ===== ===== Saving the data =====
  
-As we stated in the form, we now have to create a "default_createsave" action to save the new data.+As we stated in the form, we now have to create a "default:createsave" action to save the new data.
  
 Initially, we retrieve a record, that is filled with the data sent by the form. The URL parameters ($_GET) or posted ($_POST), are accessible via the param() method of the controllers. Initially, we retrieve a record, that is filled with the data sent by the form. The URL parameters ($_GET) or posted ($_POST), are accessible via the param() method of the controllers.
Line 86: Line 88:
 <code php> <code php>
         $rep = $this->getResponse('redirect');         $rep = $this->getResponse('redirect');
-        $rep->action = 'news~default_index';+        $rep->action = 'news~default:index';
         return $rep;         return $rep;
 </code> </code>
Line 103: Line 105:
  
         $rep = $this->getResponse('redirect');         $rep = $this->getResponse('redirect');
-        $rep->action = 'news~default_index';+        $rep->action = 'news~default:index';
         return $rep;         return $rep;
     }     }
Line 110: Line 112:
 You can now display the list of news one more time and reach the form. You can now display the list of news one more time and reach the form.
  
----- 
-   * Next : [[en:tutorials:main:end|Next]] 
-   * Previous : [[en:tutorials:main:using-dao|Using a DAO]] 
-   * [[en:tutorials:main|Back to the summary]] 
  

en/tutorials/main/news-form.1189925575.txt.gz · Last modified: 2007/12/18 11:19 (external edit)

Recent changes RSS feed Creative Commons License