Welcome Guest, Not a member yet? Register   Sign In
Filling form variables
#1

[eluser]jwburnside[/eluser]
Hey everyone.

I was wondering about best practices for filling in form data that might come from either a database or from post data (or neither), specifically concerning empty form variables, which throw an error:

A simplified version that I have been doing is this:


Code:
//View
<li>&lt;?= form_label('Nickname', 'nickname', array('class' => '')); ?&gt;
    &lt;?= form_input(array('id' => 'nickname', 'name' => 'nickname', 'size' => 60, 'value' => set_value('nickname',$nickname))); ?&gt;
      </li>

Code:
//Controller
if(!isset($_POST['form_return'])) {

  if($row)
     $view_data = array(...the database data);
  else
     $view_data = array(...Here is where I have to define empty form variables);
}

else
  $view_data = $_POST

It works fine, but I would rather not have to set empty variables for the form should there be no database or $_POST data. How is this best accomplished with Codeigniter?

Any help would be appreciated.
#2

[eluser]digfish[/eluser]
Well your problem is mine too. I don't see any other way than filling the form fields yourself than using the set_value() function, using its 2nd parameter to enter the values fetched from the database. I know that is not so well. But you should (I have only two weeks of CodeIgniter use) there is much thing in this framework that you should do all the work by yourself. One is the layouts, I'd have to use a third-party framework (OcularLayout) in order to implement it with CI . I believe, since no one as ever placed a reply is that there is no simple soultion for your (which is mine too) question.




Theme © iAndrew 2016 - Forum software by © MyBB