[eluser]tente[/eluser]
Finally I did it. It was a nigthmare because of the deadline but I did as well as I could.
We're talking about three different forms with almost 300 fields per form (lots of tables).
My recomendations are:
Name the inputs with a prefix and a number or a couple of numbers if it's a table.
It's very tempting giving descriptives names to the fields (like project_name or so) but for getting the input data or storing in the DB, could be madness.
Get input example:
Code:
for ($i = 1; $i < 6; $i++)
{
for ($j = 1; $j < 7; $j++)
{
$name = 'des_11_r_'.$i.'_c_'.$j;
$inputs[$name] = $this->input->get_post($name, TRUE);
}
}
Pretty easy, right? This case was for a table, for just data you only need one loop. If you think you can get lost because of the naming convention, I recommend using an index file or similar. In my case it was easy because I had to use two languages and I named the lang variables almost the same as inputs.
Name input fields and database fields with almost the same name.
Inserting or updating data would be like closing a zipper.
Example:
Code:
function save_data($values, $type)
{
if ($type == 0)
{
$this->db->insert('desarrollo', $values);
return $this->db->insert_id();
}
else
{
$this->db->where('des_id', $values['des_id']);
$this->db->update('desarrollo', $values);
return $values['des_id'];
}
}
Split the form in pages:
It's easier for the user and the usability. So I used like three related tables for the same form.
Use as much CodeIgniter as you can
CI is da best
Things like declaring inputs with the form helper and then call them in the view makes life easier.
Example:
Code:
for ($i = 1; $i < 9; $i++)
{
$row = ($i < 10) ? "0".$i : $i;
$name = 'dgas_stotal_'.$row;
$inputs[$name] = array('name' => $name, 'id' => $name, 'maxlength' => '15', 'class' => 'input_table_b', 'value' => $values[$name], 'readonly' => 'readonly');
}
....
<td><?php echo form_input($inputs['dgas_stotal_01']); ?></td>
So, that are the main things I'd like to highlight, If you think something's wrong or could be a better aproach, please let me know.