Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 540165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:12:42+00:00 2026-05-13T10:12:42+00:00

Which is right? notice in the second option, I’m passing the form values using

  • 0

Which is right? notice in the second option, I’m passing the form values using the $_POST variable. Whereas the first option, I call and assign variables for each form field.

I’ve seen this …

<validation code> ....

$todo = array(
      'name'=>$this->input->post('title'),
      'description'=>$this->input->post('description')
);

$this->Todo_model->add($todo); 

But I’ve also seen the following …

$records['email']    = "trim|required|min_length[4]|xss_clean";
...
...    

$this->validation->set_rules($records);

if ($this->validation->run())
{
   $this->account_model->saveAccountSettings("sam", $_POST);
   $this->session->set_flashdata('message', 'Done!');            

   redirect('account/settings');
} else {
...
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:12:43+00:00Added an answer on May 13, 2026 at 10:12 am

    I tend to use a mix of your two examples. I’m pretty sure things like trim won’t modify the actual post data, so you can only take advantage of it if you go through the validation framework to get the data. I actually never access POST directly anymore using CI.

    Plus I’d be worried in your second example about just shoving POST into my model. What happens if someone clever adds “lastname” to the post data sent in and your db column is named the same? Even though you weren’t expecting to deal with that data now you’ve got unvalidated data coming in. That’s why I employ part of your first example and manually pull out the items I want to save into an array first.

    So I’d recommend a hybrid.

    Normally my code looks something like this:

    $fields['email']    = "trim|required|valid_email|min_length[4]|xss_clean";
    ...
    ...    
    
    $this->validation->set_rules($fields);
    
    if ($this->validation->run())
    {
       $account = new array();
       $account['id'] = $accountId; //wherever you get the Id from
       $account['email'] = $this->validation->email;
    
       $this->account_model->save($account);
       $this->session->set_flashdata('message', 'Done!');            
    
       redirect('account/settings');
    } else {
    ...
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which is the right way of declaring a global javascript variable? The way I'm
While learning an example from learn-you-a-haskell which right triangle that has integers for all
I have a multi-select box which has 2 buttons on the right which are
Triple-clicking the mouse to select a paragraph sets document.getSelection().leftOffset to 0 (which seems right)
We have a script right now which our Windows users run on a Linux
I Have wrote a question which got a right answer here about emysql encoding.
In my app I have a stickman, which moves to right when you click
Which do you suggest: data Direction = Left | Right type Direction = Bool
Right now I have this SQL query which is valid but always times out:
I am right now running a bash script in which i need to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.