Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASM
I am developing a simple registration form that validates with php. problem is rather than the validation echoing on screen once I click the submit button nothing happens, no error or brake it dose not show me what the error is, I believe my logic is correct but I believe there may be a mistake.

would appriciate any advise or identification of my problem


register.php
PHP
<?php
require_once 'core/init.php';

if(Input::exists()) {
	$validate = new Validate();
	$validation = $validate->check($_POST, array(
		'username' => array(
			'required' => true,
			'min' => 2,
			'max' => 20,
			'unique' => 'users'
		),
		'password' => array(
			'required' => true,
			'min' => 6
		),	
		'password_again' => array(
			'required' => true,
			'matches' => 'password'
		),	
		'name' => array(
			'required' => true,
			'min' => 2,
			'max' => 50
		),
	));

	if($validation->passed()) {
		echo 'Passed';
	}	else {
			print_r($validation->errors());
	}

}	
?>

<form action="" methord="post">
	<div class="field">
		<lable for="username">Username</lable>
		<input type="text" name="username" id="username" value="<?php echo escape(Input::get('username')); ?>" autocomplete="off">
	</div>

	<div class="field">
		<lable for="password">Choose Your Password</lable>
		<input type="password" name="password" id="password">
	</div>

	<div class="field">
		<lable for="password_again">Verify Password</lable>
		<input type="password" name="password_again" id="password_again">
	</div>

	<div class="field">
		<lable for="name">Your Name</lable>
		<input type="text" name="name" value="<?php echo escape (Input::get('name')); ?>" id="name">
	</div>

	<input type="submit" value="Register">
</form>


validate.php
PHP
<?php
class Validate {
	private $_passed = false,
			$_errors = array(),
			$_db = null;

	public function __contruct() {
		$this->_db = DB::getInstance();
	}

	public function check($source, $items = array()) {
		foreach($items as $item => $rules) {
			foreach($rules as $rule => $rule_value) {
				
				$value = $source[$item];

				if($rule == 'required' && empty($value)) {
					$this->addError("{$item} is required")
				} else {

				}

			}
		}

		if(empty($this->_errors)) {
			$this->_passed = true;
		}

		return $this;
	}

	private function addError() {
		$this->_errors[] = $error;
	}

	public function errors() {
		return $this->_errors;
	}

	public function passed() {
		return $this->_passed;
	}
}
Posted
Updated 8-Jan-14 7:42am
v2

In addition to solution 1, two typo spotted in register.php:
1. "methord", should be "method"
2. "lable", should be "label"
Is "escape" a function in "init.php"?
There is no inclusion of "validate.php" in "register.php". Was it in "init.php"?
 
Share this answer
 
v3
your syntax error checking is off. open php.ini file and then set
error_reporting = E_ALL

you have syntax error on validate.php on line 18, semicolon is missing.

You have syntax error on register.php on line 25. A comma is visible which should not be there.

there might be more.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900