Welcome Guest, Not a member yet? Register   Sign In
Form not working... probably just a silly error.
#1

[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>
&lt;?= form_open('outreach/save_visitor'); ?&gt;

  &lt;?= form_fieldset('Name') ?&gt;
   <div>
    &lt;?= form_label('First Name','first') ?&gt;
    &lt;?= form_input('first','','id="first"') ?&gt;
    &lt;?= form_error('first') ?&gt;
   </div>
   <div>
    &lt;?= form_label('Last Name','last') ?&gt;
    &lt;?= form_input('last','','id="last"') ?&gt;
    &lt;?= form_error('last') ?&gt;
   </div>
  &lt;?= form_fieldset_close() ?&gt;

  &lt;?= form_fieldset('Gender') ?&gt;
   &lt;?= form_error('gender') ?&gt;
   <div>
    &lt;?= form_label('Female','gender_female') ?&gt;
    &lt;?= form_radio('gender','',TRUE,'id="gender_female"') ?&gt;
   </div>
   <div>
    &lt;?= form_label('Male','gender_male') ?&gt;
    &lt;?= form_radio('gender','',FALSE,'id="gender_male"') ?&gt;
   </div>
  &lt;?= form_fieldset_close() ?&gt;

  &lt;?= form_fieldset('Contact') ?&gt;
   <div>
    &lt;?= form_label('Email','email') ?&gt;
    &lt;?= form_input('email','','id="email"') ?&gt;
   </div>
   <div>
    &lt;?= form_label('Address 1','address1') ?&gt;
    &lt;?= form_input('address1','','id="address1"') ?&gt;
   </div>
   <div>
    &lt;?= form_label('Address 2','address2') ?&gt;
    &lt;?= form_input('address2','','id="address2"') ?&gt;
   </div>
   <div>
    &lt;?= form_label('Home Phone','home_phone') ?&gt;
    &lt;?= form_input('home_phone','','id="home_phone"') ?&gt;
    &lt;?= form_error('home_phone') ?&gt;
   </div>
   <div>
    &lt;?= form_label('Cell Phone','cell_phone') ?&gt;
    &lt;?= form_input('cell_phone','','id="cell_phone"') ?&gt;
    &lt;?= form_error('cell_phone') ?&gt;
   </div>
  &lt;?= form_fieldset_close() ?&gt;

&lt;?= form_submit('submit', 'Submit') ?&gt;

&lt;?= form_close() ?&gt;
</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!




Theme © iAndrew 2016 - Forum software by © MyBB