Advertisement
gareth126

2.0 ex 3

Nov 19th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. <?php
  2.  
  3. //users controller code
  4.  
  5.  public function adduserAction()
  6.     {
  7.         //assign post vars
  8.         $username = $this->_request->getPost('name');
  9.         $password = $this->_request->getPost('password');
  10.         $details = $this->_request->getPost('details');
  11.        
  12.         //bit of housework
  13.         $username = mysql_escape_string($username);
  14.         $password = mysql_escape_string($password);
  15.         $details = mysql_escape_string($details);
  16.        
  17.         //do some error checking on the content (basic != '' validation)
  18.         if ($username != '' && $password != '' && $details != ''){
  19.                
  20.             $this->view->userName = $username;
  21.             $this->view->userPassword = $password;
  22.             $this->view->userDetails = $details;
  23.            
  24.             //redirect them to the confirmation page / action
  25.             $this->render('confirmuser');
  26.            
  27.         }else{
  28.             //show messages depending on what they didnt fill in and don't redirect to new action
  29.             if ($username == '' || $username == 'please insert a username!'){
  30.                 $username = 'please insert a username!';
  31.             }
  32.             if ($details == '' || $details == 'please tell us about yourself!'){
  33.                 $details = 'please tell us about yourself!';
  34.             }
  35.             $this->view->userName = $username;
  36.             $this->view->userPassword = $password;
  37.             $this->view->userDetails = $details;
  38.         }
  39.        
  40.     }
  41.  
  42.     public function confirmuserAction(){
  43.        
  44.     }
  45.  
  46. //add user view
  47. <br /><br />
  48. <div id="view-content">
  49.     <h1>Add a new user to the system form!</h1>
  50.     <form action="adduser" method="post" enctype="application/x-www-form-urlencoded">
  51.         <fieldset>
  52.             <legend>Add new user</legend>
  53.             <dl>
  54.                 <dt><label for="name">User name:</label></dt>
  55.                 <dd><input type="text" name="name" value="<?php echo $this->userName; ?>" /></dd>
  56.                
  57.                 <dt><label for="password">User password:</label></dt>
  58.                 <dd><input type="password" name="password" value="<?php echo $this->userPassword; ?>" /></dd>
  59.                
  60.                 <dt><label for="details">User details:</label></dt>
  61.                 <dd><textarea rows="20" cols="20" name="details"><?php echo $this->userDetails; ?></textarea></dd>
  62.                
  63.                 <dt><label for="submit" style="display:none;">Add user:</label></dt>
  64.                 <dd><input type="submit" name="submit" value="Add user" /></dd>
  65.             </dl>
  66.         </fieldset>
  67.     </form>
  68. </div>
  69.  
  70. //confirm user view
  71. <br /><br />
  72. <div id="view-content">
  73.     <h1>Confirm user</h1>
  74.     <p>The details for the users are as follows:</p>
  75.    
  76.     <ul>
  77.         <li>Name: <?php echo $this->userName; ?></li>
  78.         <li>Password: <?php echo $this->userPassword; ?></li>
  79.         <li>Details: <?php echo $this->userDetails; ?></li>
  80.     </ul>
  81.  
  82. </div>
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement