CodeIgniter Forums
Form Generation Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Form Generation Library (/showthread.php?tid=16439)



Form Generation Library - El Forum - 12-29-2009

[eluser]combatCoder[/eluser]
HAPPY HOLIDAYS ALL!!!!

I am creating a dynamic report generator and now I am stuck.
Code:
$this->form
->open('report/generate', 'form_name')

// Generate the select and where of the SQL query from form.

->submit('Generate Report')
->model('query_model', 'run_query')
->validate();
if($this->form->valid)
{
    redirect('report/success');
}
$data['form'] = $this->form->get();
$data['errors'] = $this->form->errors;
$this->load->view('form/form_view', $data);

Here is the model:
Code:
function run_query(&form;, $data)
{
  //Generate the query
  //I.e. #SQL = "SELECT ...";
  $query = $this->db->query($SQL);
  if($query->num_rows() > 0)
  {
    foreach($query->result_array() as $row)
    {
      $results[] = $row;
    )
  }
  $var_dump($results); // I can see the results from the query when I check.
  $die();
  return $results;
}

OK everything works great, but how can I pass my results back to the form so I can view the results after the form is validated? LOL, again all I can see is that tree and not the forest... Also, as stated above I can see the data in the method; however, since I did not assign the method call to a variable not sure how the reference to the form works here.

Any and all assistance will get greatly appreciated.


Form Generation Library - El Forum - 12-29-2009

[eluser]dinhtrung[/eluser]
@combatCoder: why don't you use session or flashdata to store your query information, then when the page reload, you could use them later?
Code:
/* Controller : Generate Report */
function index()
{
   $this->form->open()
//        -> ...
          ->model('report_m', 'saveSql')
          ->onsuccess('redirect', $this->uri->uri_string());
   $data['form'] = $this->form->get();
   $data['errors'] = $this->form->errors;
   $sql = $this->session->userdata('report_saved_sql');
   if ($sql) $data['report_content'] = $this->db->query($sql)->result();
   else $data['report_content'] = '';
   $this->load->view('report_view', $data);
}

/* Model : report_m */
function saveSql(&$form, $data)
{
   /* Construct SQL $sql from $data */
   $this->session->set_userdata('report_saved_sql', $sql);
}

/* View : report_view */
if (! empty($errors)) print $errors;
if (! empty($form)) print $form;
if (! empty($report_content)) print $report_content;



Form Generation Library - El Forum - 12-30-2009

[eluser]macigniter[/eluser]
[quote author="combatCoder" date="1262137214"]
OK everything works great, but how can I pass my results back to the form so I can view the results after the form is validated? LOL, again all I can see is that tree and not the forest... Also, as stated above I can see the data in the method; however, since I did not assign the method call to a variable not sure how the reference to the form works here.

Any and all assistance will get greatly appreciated.[/quote]

Did you try using a hidden field as a container? Then in the model you could use

Code:
$form->set_value('hidden_field', $content);

In the controller you could then access the post var 'hidden_field' with the inputs of the model.


Form Generation Library - El Forum - 12-31-2009

[eluser]seanloving[/eluser]
Happy New Year

I posted a question here
http://ellislab.com/forums/viewthread/92212/P285/#689270
about callbacks not working with my combination of Form Gen Library v1.0 (macigniter) with HMVC ME 5.2.30 (wiredesignz)

If anybody on this thread knows how to make regular callbacks work with my configuration please let me know, thanks.

-Sean Loving


Form Generation Library - El Forum - 12-31-2009

[eluser]Moru789[/eluser]
Happy new year!

Wonderful way of doing the boring tasks with forms :-) I just have two problems:

1.
When I add a select-box I want to set the size to 10 and at the same time set the event "onDblClick=...". How is this possible? I have tried array('size="10"', 'onDblClick="..."') but I end up with this line:

size="10"" (note the doublequotes)

My workaround at the moment is this:
Code:
->select('list1', $list1, '', '', '', 'size="1"')
$form = str_replace('size="1"', 'size="10" onDblClick="..."', $form);
This seems a bit awkward but works :-)


2.
My second problem is with placing the zip-code and city name on the same row. I get it working as in the examples with one zip-code/city on a form but if I try two I end up with strange results, frameset isn't properly ended and so on. Sadly I deleted the source and gave up before I found this thread so have no example at the moment. I had the two addresses in two different framesets at the moment so mabe that was making troubles.


Form Generation Library - El Forum - 12-31-2009

[eluser]macigniter[/eluser]
[quote author="Moru789" date="1262303873"]1. When I add a select-box I want to set the size to 10 and at the same time set the event "onDblClick=...". How is this possible? I have tried array('size="10"', 'onDblClick="..."') but I end up with this line:

size="10"" (note the doublequotes)

My workaround at the moment is this:
Code:
->select('list1', $list1, '', '', '', 'size="1"')
$form = str_replace('size="1"', 'size="10" onDblClick="..."', $form);
This seems a bit awkward but works :-)[/quote]

Simply do (comma separated):

Code:
->select('list1', $list1, '', '', '', 'size=10,onDblClick="..."')



Form Generation Library - El Forum - 12-31-2009

[eluser]dinhtrung[/eluser]
1 - Like this:
Code:
->select('list1' $list1, '', '', '', 'size=1 onDblClick=...')
The form lib can automatically parse the data by = character. Look for the function named _att_string() in the source code for details.
2 - I don't think this could give some error. After all, it's just another textbox with custom callback. Nothing more. Try:
Code:
->text('city_src', 'Source City')
->text('zip_src', 'Source Zipcode')
->text('city_dst', 'Destination City')
->text('zip_dst', 'Destination Zipcode')
Just make the name different. I tested without any error.


Form Generation Library - El Forum - 12-31-2009

[eluser]Moru789[/eluser]
Neither of those work with onDblClick, I only get the size attribute, the second is totally ignored. I have tried with space and comma-separated list but neither work.

(About the city/zip, try to put them on the same line and you will see what I mean. What you are using there is what I am doing now since I can't get it working on the same line, dinhtrung.)

Edit: No, forget about that last problem. After testing it with the latest verion 1.0 it works perfectly, thanks!


Form Generation Library - El Forum - 01-01-2010

[eluser]macigniter[/eluser]
[quote author="Moru789" date="1262305125"]Neither of those work with onDblClick[/quote]

It works with lowercase "ondblclick". As far as I know you shouldn't use camelcase in html attributes.


Form Generation Library - El Forum - 01-01-2010

[eluser]hugle[/eluser]
[quote author="Moru789" date="1262305125"]Neither of those work with onDblClick, I only get the size attribute, the second is totally ignored. I have tried with space and comma-separated list but neither work.

(About the city/zip, try to put them on the same line and you will see what I mean. What you are using there is what I am doing now since I can't get it working on the same line, dinhtrung.)

Edit: No, forget about that last problem. After testing it with the latest verion 1.0 it works perfectly, thanks![/quote]

which version of Form Generation Library are you using?