Welcome Guest, Not a member yet? Register   Sign In
SOLVED: set_value('field_name') returns "Array"
#1

[eluser]Unknown[/eluser]
I have looked around the internet and these forums and can't find the answer. I am trying to repopulate my form on validation failure but the fields are being repopulated with "Array" instead of the data that was posted to the controller.


Here is the controller code.

Code:
<?php
class Contact extends Controller
{
  function Contact(){
    parent::Controller();
    
  }

  function index(){
    $this->load->library('form_validation');

    $this->form_validation->set_rules('first_name', 'First Name', 'required');
    $this->form_validation->set_rules('last_name', 'Last Name', 'required');
    $this->form_validation->set_rules('salutation', 'Salutation', 'required');
    $this->form_validation->set_rules('email_address', 'Email', 'required');

    if ($this->form_validation->run() == FALSE)
        {
            $args = array('model_line_name'=>'contact','model_name'=>null);
      $this->load->view('common/header',$args);
      $this->load->view('contact_us_view');
      $this->load->view('common/footer');
        }
        else
        {
            echo "Form Success";
        }
    
  }
}
?>

The View is as follows

Code:
<div id="contact_form">
&lt;?php
  echo validation_errors();
  echo form_open('contact');
  echo "<label for='salutation'>Salutation:</label>";
  ?&gt;
  <select name ="salutation" id ="salutation">
    <option value ="Mr." &lt;?php echo set_select('salutation','Mr.',TRUE); ?&gt; >Mr.</option>
    <option value ="Mrs." &lt;?php echo set_select('salutation','Mrs.'); ?&gt; >Mrs.</option>
    <option value ="Ms." &lt;?php echo set_select('salutation','Ms.'); ?&gt; >Ms.</option>
    <option value ="Dr." &lt;?php echo set_select('salutation','Dr.'); ?&gt; >Dr.</option>
  </select>
  
  &lt;?php
  echo "<label for='first_name'>First Name:</label>";
  echo form_input('first_name',array('value'=>set_value('first_name'),'id'=>'first_name'));
  echo "<label for='last_name'>Last Name:</label>";
  echo form_input('last_name',array('value'=>set_value('last_name'),'id'=>'last_name'));
  echo "<label for='email_address'>Email:</label>";
  echo form_input('email_address',array('value'=>set_value('email_address'),'id'=>'email_address'));
  echo "<label for='phone_number'>Phone:</label>";
  echo form_input('phone_number',array('value'=>set_value('phone_number'),'id'=>'phone_number'));

  echo form_submit('contact_submit','Contact Us');
  echo form_fieldset_close();
?&gt;
</div>

I am not sure what I am missing. I will keep trying various permutations of code but it would be helpful if someone else has already characterized this issue.

Thanks,

Daniel
#2

[eluser]Unknown[/eluser]
Definitely my bad on this one. I somehow got my wires crossed on how to use the form_input helper function.

I needed an id so I entered the following

Code:
form_input('first_name',array('value'=>set_value('first_name'),'id'=>'first_name'));

When using an array form_input takes only one argument like so

Code:
form_input(array('name'=>'first_name', 'value'=>set_value('first_name'),'id'=>'first_name'));

Anyway it is all fixed now.




Theme © iAndrew 2016 - Forum software by © MyBB