[eluser]Unknown[/eluser]
Hey there!
I'm new to CodeIgniter, and I've having problem submitting a form.
Here is the code for my controller:
Code:
<?php
class Outreach extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->add_visitor();
}
public function add_visitor()
{
$this->add_visitor_form();
}
private function add_visitor_form()
{
$data['title'] = "Add Visitor to Database";
$data['page_content'] = $this->parser->parse('outreach/add_visitor_form', $data, TRUE);
$this->parser->parse('outreach/main_view', $data);
}
public function save_visitor()
{
$this->form_validation->set_rules('first', 'First Name', 'required');
$this->form_validation->set_message('first', 'You must enter the visitor\'s first name!');
$this->form_validation->set_rules('last', 'Last Name', 'required');
$this->form_validation->set_message('last', 'You must enter the visitor\'s last name!');
$this->form_validation->set_rules('home_phone', 'Home Phone Number', 'callback_validate_phone_number');
$this->form_validation->set_message('home_phone', 'Please enter a valid home phone number!');
$this->form_validation->set_rules('cell_phone', 'Cell Phone Number', 'callback_validate_phone_number');
$this->form_validation->set_message('cell_phone', 'Please enter a valid cell phone number!');
if ($this->form_validation->run())
{
echo '¡¡ES MUY BUENO!!';
}
else
{
echo '¡¡NO ES BUENO!! :(';
}
$this->add_visitor_form();
}
private function validate_phone_number($value)
{
$value = trim($value);
if ($value == '')
{
return TRUE;
}
else
{
if (preg_match('/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/', $value))
{
return preg_replace('/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/', '($1) $2-$3', $value);
}
else
{
return FALSE;
}
}
}
}
AND here is the code for my form's view:
Code:
<div>
<?= form_open('outreach/save_visitor'); ?>
<?= form_fieldset('Name') ?>
<div>
<?= form_label('First Name','first') ?>
<?= form_input('first','','id="first"') ?>
<?= form_error('first') ?>
</div>
<div>
<?= form_label('Last Name','last') ?>
<?= form_input('last','','id="last"') ?>
<?= form_error('last') ?>
</div>
<?= form_fieldset_close() ?>
<?= form_fieldset('Gender') ?>
<?= form_error('gender') ?>
<div>
<?= form_label('Female','gender_female') ?>
<?= form_radio('gender','',TRUE,'id="gender_female"') ?>
</div>
<div>
<?= form_label('Male','gender_male') ?>
<?= form_radio('gender','',FALSE,'id="gender_male"') ?>
</div>
<?= form_fieldset_close() ?>
<?= form_fieldset('Contact') ?>
<div>
<?= form_label('Email','email') ?>
<?= form_input('email','','id="email"') ?>
</div>
<div>
<?= form_label('Address 1','address1') ?>
<?= form_input('address1','','id="address1"') ?>
</div>
<div>
<?= form_label('Address 2','address2') ?>
<?= form_input('address2','','id="address2"') ?>
</div>
<div>
<?= form_label('Home Phone','home_phone') ?>
<?= form_input('home_phone','','id="home_phone"') ?>
<?= form_error('home_phone') ?>
</div>
<div>
<?= form_label('Cell Phone','cell_phone') ?>
<?= form_input('cell_phone','','id="cell_phone"') ?>
<?= form_error('cell_phone') ?>
</div>
<?= form_fieldset_close() ?>
<?= form_submit('submit', 'Submit') ?>
<?= form_close() ?>
</div>
When I submit this form, I am simply getting a blank page. What gives? I don't see anything that I could be doing wrong, but there's obviously something. Any help would be GREATLY appreciated!