@@ -62,7 +62,7 @@ example.
6262The Form
6363========
6464
65- Using a text editor, create a form called **Signup .php **. In it, place this
65+ Using a text editor, create a form called **signup .php **. In it, place this
6666code and save it to your **app/Views/ ** folder::
6767
6868 <html>
@@ -75,29 +75,29 @@ code and save it to your **app/Views/** folder::
7575
7676 <?= form_open('form') ?>
7777
78- <h5>Username</h5>
79- <input type="text" name="username" value="" size="50" / >
78+ <h5>Username</h5>
79+ <input type="text" name="username" value="<?= set_value('username') ?> " size="50">
8080
81- <h5>Password</h5>
82- <input type="text" name="password" value="" size="50" / >
81+ <h5>Password</h5>
82+ <input type="text" name="password" value="<?= set_value('password') ?> " size="50">
8383
84- <h5>Password Confirm</h5>
85- <input type="text" name="passconf" value="" size="50" / >
84+ <h5>Password Confirm</h5>
85+ <input type="text" name="passconf" value="<?= set_value('passconf') ?> " size="50">
8686
87- <h5>Email Address</h5>
88- <input type="text" name="email" value="" size="50" / >
87+ <h5>Email Address</h5>
88+ <input type="text" name="email" value="<?= set_value('email') ?> " size="50">
8989
90- <div><input type="submit" value="Submit" / ></div>
90+ <div><input type="submit" value="Submit"></div>
9191
92- </form >
92+ <?= form_close() ? >
9393
9494 </body>
9595 </html>
9696
9797The Success Page
9898================
9999
100- Using a text editor, create a form called **Success .php **. In it, place
100+ Using a text editor, create a form called **success .php **. In it, place
101101this code and save it to your **app/Views/ ** folder::
102102
103103 <html>
@@ -121,6 +121,14 @@ this code and save it to your **app/Controllers/** folder:
121121
122122.. literalinclude :: validation/001.php
123123
124+ The Routes
125+ ==========
126+
127+ Then add routes for the controller in **app/Config/Routes.php **:
128+
129+ .. literalinclude :: validation/039.php
130+ :lines: 2-
131+
124132Try it!
125133=======
126134
@@ -142,11 +150,15 @@ the **Validation class** inside. See :ref:`controllers-validating-data`.
142150Explanation
143151===========
144152
145- You'll notice several things about the above pages:
153+ You'll notice several things about the above pages.
146154
147- The form (**Signup.php **) is a standard web form with a couple of exceptions:
155+ signup.php
156+ ----------
148157
149- #. It uses a :doc: `form helper </helpers/form_helper >` to create the form opening. Technically, this
158+ The form (**signup.php **) is a standard web form with a couple of exceptions:
159+
160+ #. It uses a :doc: `form helper </helpers/form_helper >` to create the form opening
161+ and closing. Technically, this
150162 isn't necessary. You could create the form using standard HTML.
151163 However, the benefit of using the helper is that it generates the
152164 action URL for you, based on the URL in your config file. This makes
@@ -159,9 +171,15 @@ The form (**Signup.php**) is a standard web form with a couple of exceptions:
159171 This function will return any error messages sent back by the
160172 validator. If there are no messages it returns an empty string.
161173
162- The controller (**Form.php **) has one method: ``index() ``. This method
163- uses the Controller-provided ``validate() `` method and loads the form helper and URL
164- helper used by your view files. It also runs the validation routine.
174+ Form.php
175+ --------
176+
177+ The controller (**Form.php **) has one property: ``$helpers ``.
178+ It loads the form helper used by your view files.
179+
180+ The controller has one method: ``index() ``. This method returns
181+ the **signup ** view to show the form when a non-POST request comes. Otherwise, it
182+ uses the Controller-provided ``validate() `` method. It also runs the validation routine.
165183Based on whether the validation was successful it either presents the
166184form or the success page.
167185
@@ -171,6 +189,7 @@ Add Validation Rules
171189Then add validation rules in the controller (**Form.php **):
172190
173191.. literalinclude :: validation/002.php
192+ :lines: 2-
174193
175194If you submit the form you should see the success page or the form with error messages.
176195
0 commit comments