Login Retreive lost passwordRegister

Forum Index / General / INSERT / UPDATE multiple tables

[ This topic is unsolved! ]

  John Doe 16 April 12 / 14:03  
Hi! It would be a nice feature if the db option supports inserting and updating to multiple tables; without the need of handling the datastorage of the joined table myself. Is this be possible?

  Johan Wiegel (Admin) 16 April 12 / 14:13  
checkout this function: addJunctionTable

  John Doe 16 April 12 / 14:35  
Changed at 16 April 12 / 14:54
As I understand this function makes it possible to store array values of a checkbox or select field into a seperated table, but not the data of a separated list of multiple fields... right?

I'll try to explain using the following tables:

contacts (id, company_id, firstname, lastname)
companies (id, company_name)

Then the form would have the fields firstname, lastname and company name. I would really really appreciate it if the form itself saves the 3 fields to the corresponding tables.

Something like:

$dbForm->AddJoinTable('companies', 'id', 'company_id'); // tablename, key, foreign key

The dbFormHandler can compare the fieldnames with the columnnames of the tables, so the insert and update statements won't contain column names that don't exist. Like this:

// Data array, like FormHandler normally populates
$data = array(
   'firstname' => 'John',
   'lastname' => 'Doe',
   "company_name' => 'Example',

// Table array, like FormHandler could potentially populate when using AddJoinTable()
$tables = array('contacts', 'companies');

// Execute insert query
foreach ($tables as $table) {
   insert($table, $data);

function insert($table, $data) {
   // Fetch keynames of posted data
   $data_keys = array_keys($data);

   // Fetch list of columns names in table
   $result = mysql_query("SHOW COLUMNS FROM " . $table);

   // Create new insert query
   $insert = "INSERT INTO " . $table . " SET ";

   $i = 0;
   while ($row = mysql_fetch_assoc($result)) {
      if (in_array($row['Field'], $data_keys))
         $insert .= ($i ? ", " : "") . $row['Field'] = '" . $data[$row['Field']] . "'";



  Johan Wiegel (Admin) 17 April 12 / 10:02  
That is not what the junctiotable does.

What you descibe is what we call subforms, something on our wishlist.

It's a work in progress, we had a working beta version, but it was to complex, we have better idea's but no time to develop it yet

  Iyas 24 April 12 / 03:55  
Yes, John Doe. What you've been asking is what they call subforms.

Johan and the team is working on the subforms.
I know, because I already asking for the same before you! :)

FH is great!! So great that I've abandoned many php frameworks just because they don't have form helper as great as FH.

  John Doe 11 May 12 / 10:29  
Iyas, I totally agree! Same counts for me; I don't use Frameworks either, because FormHandler takes away the number 1 reason for using Frameworks at all: form handling.

A few missing features at the moment though:

* Subforms
* GET support
* Support for arrays as fieldnames

  Johan Wiegel (Admin) 17 October 13 / 10:02  
_GET support and array's as fieldnames need a total rewrite. Won't happen soon.

Subforms - we have some development versions, but are not satisfied with the found solutions.


© 2004 - 2017 FormHandler. All rights reserved.   -   Open source license