06-29-2008, 07:35 PM
[eluser]markanderson993[/eluser]
I am creating a registration script to work with Codeigniter, however I cannot seem to be able to insert an array into another array. How can I insert the $errors array into the $data array being passed along to the html page?
** Note: the global command will be used in the next step of developing this application **
I am creating a registration script to work with Codeigniter, however I cannot seem to be able to insert an array into another array. How can I insert the $errors array into the $data array being passed along to the html page?
Code:
<?php // home.php (Class)
Class Register extends Controller {
function Register()
{
parent::Controller();
$this->load->helper('form');
}
function index()
{
$this->template->load('register/register_view');
}
function handle()
{
if (empty($_POST['username']))
{
$errors[0] = 'Please enter your username';
} else {
$username = $_POST['username'];
global $username;
}
if ( (empty($_POST['password'])) || (empty($_POST['conf_password'])) )
{
$errors = 'Please enter your password';
} else {
$password = $_POST['password'];
global $password;
}
if ( (empty($_POST['email'])) || (empty($_POST['conf_email'])) )
{
$errors = 'Please enter your email';
} else {
$email = $_POST['email'];
global $email;
}
if ($errors)
{
global $errors;
$data['problems'] = array('One','Two','Three');
$this->template->load('register/register_view',$data);
} else {
echo 'Huge Success!';
}
}
} // End Class Home
?>
** Note: the global command will be used in the next step of developing this application **
Code:
<?php
if (isset($problems))
{
foreach($problems as $message) echo "$message<br />";
}
?>
<b>Registration Page</b>
<div id="registration"><table>
<?=form_open('register/handle')?>
<tr><td>Username:</td><td><input type="text" name="username" /></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" /></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="conf_password" /></td></tr>
<tr><td>Email:</td><td><input type="text" name="email" /></td></tr>
<tr><td>Confirm Email:</td><td><input type="text" name="conf_email" /></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Register" /></td></tr>
</table></div><!--Registration-->