Welcome Guest, Not a member yet? Register   Sign In
Very big form
#1

[eluser]tente[/eluser]
Hi, I'm thinking about how to handle a very very big form.

There are more than 300 fields/inputs (most in big tables).

My aproach is:

- Split the form in several pages.
- Save every form page in a DB table once it's finished, so the user can continue the form by pieces.
- Once the user has reached the end of the form, mark the table entries as valid.

And my questions are:
- Should I create one table per page or a very big one?
- Is this a good aproach?
- Besides the form helper, the form validator class and the input class, is there any other class/feature or trick to take into account in CodeIgniter?

Any thoughts would be much appreciated.

Cheers!

Tente
#2

[eluser]BrokenLegGuy[/eluser]
I recently finished a project doing more or less the same thing (40 fields).
I placed all the fields into three tables.
Table one - Contact information
Table two - Company information
Table three - Request Information

Obviously you'll need to break it out according to the data you're gathering. If that's what you want to do.

I broke it up into pages as well and had validation run on every "step". Also I would store in the db the "step" they left off on and return them to that step when they come back.

I also saved all file uploads for the last step so all of that could be done at once. I only had six uploads so it wasn't a big deal to do so.

The only other things I can think of off the top of my head would be
turning on some security features.
Code:
config/config.php

$config['global_xss_filtering'] = TRUE;
$config['csrf_protection'] = TRUE;

Hope this helps
#3

[eluser]tente[/eluser]
Thanks for your tips! (I'll use the config ones)

And yes, I'm splitting in three too (data entries and two big tables).

There's other main issue: text fields. In the past I've seen tables that only store text fields (id + text). Maybe for visual purposes in phpmyadmin that aproach is better. On the other hand, I think I'll keep varchars in the table.
#4

[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 Wink

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>&lt;?php echo form_input($inputs['dgas_stotal_01']); ?&gt;</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.




Theme © iAndrew 2016 - Forum software by © MyBB