• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form validation & view within a one function

Alright this question may sound silly & sorry for that as i am a  newbie to CI. 

Here's my problem, right now to validate & show a form am i using 2 functions in one of my controllers.

for example I have a controller named "Customer". the web application i am working on have feature to "Add customers" mainly the adding a customer done via a form interface.

so in my controller (Customer) i have 2 functions like this.

1. public function new_vehicle() - This function loads the view with add customer form.

2.  public function validate_vehicle() - This function contains validation rules related to add customer form.

in the view forms action (echo form_open) is set to validate_vehicle function, this way when the user submits the form if there are errors the form will not send results to database if no errors the results will be send to database.

when a user needs to add a customer, the form can be accessed by MYSITE.com/Customer/new_vehicle, as i defined the view with this function.

when there are validation errors, as a result of invoking validate_vehicle function. the url on the browser displays as MYSITE.com/Customer/validate_vehicle.  

what i want to achieve is  load the view & validation rules within a single function. is this possible? like

 public function new_vehicle()  {

Here i am loading the view


Here i am loading validation stuff.


guide me please  .

Messages In This Thread
Form validation & view within a one function - by greenarrow - 08-02-2016, 06:00 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.