Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't my PHP form validation work? [duplicate]

Tags:

forms

php

When I try to submit a form on my site I get the following error:

Fatal error: Cannot access empty property in functions/form_validation.php on line 15

The code for form validation is:

class Validation {
    var $success;
    var $post_data;
    var $errors;
    var $delimiter;


    function Validation($HTTP_POST_DATA) {
        $this->success = true;
        $this->errors = false;
        $this->$post_data = $HTTP_POST_DATA;
        $this->delimiter = "|";
        while(list ($key, $val) = each ($this->$post_data)) {
            $this->{$key} = $val;
        }
        reset($this->$post_data);
        while(list ($key, $val) = each ($this->$post_data)) {
            if(method_exists($this, $key)) {
                $cmd = "\$this->".$key."();";
                eval($cmd);
            }
        }
    }

The code from the form page is:

 include_once($APP_ROOT . "functions/index.php");
    include_once($APP_ROOT . "functions/form_validation.php");
    $CONTINUE = TRUE;
    $valid = new Validation($_POST);
    if($CONTINUE = $valid->success) {

This code used to work just fine before we upgraded to PHP5. Any idea what I need to change to get it working again?

Thanks

like image 620
user2791808 Avatar asked Dec 09 '22 12:12

user2791808


2 Answers

$this->$post_data should be $this->post_data

In future, try looking at the line that the error message points you do, because usually that's where the problem is! ;)

like image 123
Niet the Dark Absol Avatar answered Dec 31 '22 10:12

Niet the Dark Absol


Change this:

$this->$post_data = $HTTP_POST_DATA;

To this:

$this->post_data = $HTTP_POST_DATA;
like image 32
Mark Avatar answered Dec 31 '22 11:12

Mark