开发者

CodeIgniter Error - Undefined property: CI_Input::$post

I'm开发者_开发问答 new to CodeIgniter and am trying to use the conditional below to determine whether or not the form has been submitted, and then display a certain view if it has. I got the error in the title for some reason and have been troubleshooting the problem for more than half and hour. Does anybody know how I might go about solving this problem? Thanks!

if($this->input->post->lastName){

    // load view if form was submitted

} else {

    // load other view

}


try:

if($this->input->post('lastName')){

    // load view if form was submitted

} else {

    // load other view

}


Ben,

Jayrox answer is correct, but you should be thinking of using the Form Validation class.

As stated in the Form Validation manual:

Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario:

  1. A form is displayed.
  2. You fill it in and submit it.
  3. If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data along with an error message describing the problem.
  4. This process continues until you have submitted a valid form.

On the receiving end, the script must:

  1. Check for required data.
  2. Verify that the data is of the correct type, and meets the correct criteria. For example, if a username is submitted it must be validated to contain only permitted characters. It must be of a minimum length, and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.
  3. Sanitize the data for security.
  4. Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)
  5. Prep the data for insertion in the database.

Although there is nothing terribly complex about the above process, it usually requires a significant amount of code, and to display error messages, various control structures are usually placed within the form HTML. Form validation, while simple to create, is generally very messy and tedious to implement.

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜