Posted By

djenniex on 11/17/09


Tagged

form controller


Versions (?)

Form Test Controller


 / Published in: PHP
 

Test controller for custom Form_validation class

  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Form_test extends Controller
  4. {
  5. /**
  6. * Constructor
  7. *
  8. * @return name
  9. * @access public
  10. */
  11. public function __construct()
  12. {
  13. parent::Controller();
  14. }
  15.  
  16. /**
  17.   *
  18.   *
  19.   * @access public
  20.   */
  21. public function index()
  22. {
  23. $data = array();
  24. $this->form_validation->set_rules('user_file', 'User File', 'file_required|valid_file_extension[doc|docx|pdf]');
  25. $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
  26.  
  27. if ($this->form_validation->run($this))
  28. {
  29. $first_name = $this->input->post('first_name');
  30.  
  31. $this->load->library('upload');
  32. $this->upload->initialize(array(
  33. 'upload_path' => './uploads/',
  34. 'allowed_types' => 'doc|docx|pdf',
  35. 'overwrite' => TRUE
  36. ));
  37. if ($this->upload->do_upload('user_file') === FALSE)
  38. {
  39. $upload_errors = $this->upload->display_errors();
  40. }
  41. else
  42. {
  43. $data['success'] = TRUE;
  44. $data['upload_data'] = var_export($this->upload->data(), TRUE);
  45. }
  46. }
  47. $data['form_errors'] = validation_errors();
  48. $data['user_file'] = set_value('user_file', '');
  49. $data['user_file_error'] = form_error('user_file');
  50. $data['file_info'] = var_export($_FILES, TRUE);
  51. $this->load->view('form_test', $data);
  52. }
  53. }
  54.  
  55. /* End of file name.php */
  56. /* Location: ./system/application/controller/name.php */

Report this snippet  

You need to login to post a comment.