Welcome Guest, Not a member yet? Register   Sign In
Smarty and Form Validation...
#1

[eluser]Unknown[/eluser]
I'm using Smarty in my CI project and the problem I'm having is that when I run the form validation none of the errors display in my template. The validation works because if the form is filled out incorrectly it takes me back to the form in question how ever if it's filled out correctly the code processes etc etc..I just do not get any kind of error message letting me know what is incorrectly entered. Also the set_value() function does not return anything from the previous form. I've tried using {php}echo form_error('username');{/php}, {form_error()}, {capture assign=error}{etc}{/capture} etc..I'm not sure what else to do. Also I'm not sure if this makes a difference or not but I'm also using the smartyview spark from Aaron Kuzemchak. I've emailed him for advice and nothing he has suggested has helped.

Below are my template/controllers in question..
registration.php - controller
Code:
<?php

class Registration extends CI_Controller {

public function index(){
  $header_info = array(
   'title' => 'CaseArt Designs'
  );
  $showcase = Showcase::get_showcase_items();
  $config = array(
   array(
    'name' => 'username',
    'label' => 'Username',
    'rules' => 'required|min_length[5]|max_length[9]|is_unique[users.username]'
   ),
   array(
    'name' => 'fname',
    'label' => 'First Name',
    'rules' => 'alpha'
   ),
   array(
    'name' => 'lname',
    'label' => 'Last Name',
    'rules' => 'alpha'
   ),
   array(
    'name' => 'email',
    'label' => 'Email Address',
    'rules' => 'required|is_unique[users.email]|valid_email'
   ),
   array(
    'name' => 'password',
    'label' => 'Password',
    'rules' => 'required|min_length[6]|max_length[10]'

   ),
   array(
    'name' => 'match_password',
    'label' => 'Retype Password',
    'rules' => 'required|min_length[6]|max_length[10]|matches[password]'
   ),
  );
  $data = array(
   'title' => 'CaseART Designs',
   'showcase' => Showcase::get_showcase_items()
  );
  $this->form_validation->set_rules($config);
  if($this->form_validation->run() == FALSE){
  
   $this->smartyview->render('layouts/regform.tpl', $data);
  
  } else {
   $uname = $this->input->post('username');
   $fname = $this->input->post('fname');
   $lname = $this->input->post('lname');
   $email = $this->input->post('email');
   $pwd = $this->input->post('password');
   User::create_user($uname, $fname, $lname, $email, $pwd);
   echo "Congrats! $uname";
  }
}
}

regform.tpl - main layout view..
Code:
{capture assign=val_errors}{validation_errors()}{/capture}
{include file='layouts/header.tpl' title=$title}
<!-- #Main Content -->
<div id="mainContent">
{include file='layouts/showcase.tpl' showcase=$showcase}
{include file='layouts/registration/register.tpl' val_errors=$val_errors}

</div>
&lt;!-- End Main Content --&gt;
{include file='layouts/footer.tpl'}

register.tpl - the form itself
Code:
<div id="formbox">
<h1>New User Registration</h1>
<h3>Your Details:</h3>
<p>{$val_errors}</p>
{form_open()}
<table>
  <tr>
   <td><p>Username: </p></td>
   <td>{form_input('username', set_value('username'))}</td>
   <td>{form_error('username')}</td>
  </tr>
  <tr>
   <td><p>First Name: </p></td>
   <td>{form_input('fname', set_value('fname'))}</td>
   <td>{php}echo form_error('fname');{/php}</td>
  </tr>
  <tr>
   <td><p>Last Name: </p></td>
   <td>{form_input('lname', set_value('lname'))}</td>
   <td>{form_error('lname')}</td>
  </tr>
  <tr>
   <td><p>Email: </p></td>
   <td>{form_input('email', set_value('email'))}</td>
   <td>{form_error('email')}</td>
  </tr>
  <tr>
   <td><p>Password:  </p></td>
   <td>{form_password(['name'=>'password','class'=>'txtpassword'])}</td>
   <td>{form_error('password')}</td>
  </tr>
  <tr>
   <td><p>Retype Password: </p></td>
   <td>{form_password(['name'=>'passconf','class'=>'txtpassword'])}</td>
   <td>{form_error('match_password')}</td>
  </tr>
  <tr>
   <td><p>Show Password</p></td>
   <td>{form_checkbox('showPwd')}</td>
   <td></td>
  </tr>
  <tr>
   <td></td>
   <td>{form_submit('submit', 'Register')} {form_reset('reset', 'Reset')}</td>
   <td><p>Privacy Policy</p></td>
</table>

{form_close()}
</div>
&lt;!-- End Registration Form --&gt;

This is driving me nuts and I cant figure out what I'm doing wrong or whats going on. I'm not getting any kind of errors in the apache log files and I'm not getting the typical "variable not defined" error it's like its set as an empty string so the variable is there but empty.. Is it that maybe I need to just implement smarty myself without using a spark or the fact that I'm passing "flash data" between two forms? or what?..




Theme © iAndrew 2016 - Forum software by © MyBB