Submitting content to multiple tables

Lightvision 27 Jul, 2010
is it possible to submit info to more than 2 table using the on submit?
GreyHead 27 Jul, 2010
Hi Lightvision ,

Yes, you can do a multiple selecttion on the DB Connection tab, Data will be added wherever the input names match the column names.

Bob
Grover002 17 Aug, 2010
Hmmm...tried this, but no success yet.

I have a site with a set of exercises for each user. Each exercise is one form. Upon submission I want to log the user's activity. So I have a simple table with only one column besides the standard CF columns. This column is called "Werkblad" (that's Dutch for worksheet). So in my form I add a hidden field with the name of the exercise, like this:

<input value="Werkblad 0" id="hidden_1" name="Werkblad" type="hidden" />


In DB connection I also selected this log-table, but there is no data written to it. The AutoGenerated code looks like this:
<?php
		$MyForm =& CFChronoForm::getInstance("wb0");
		if($MyForm->formparams("dbconnection") == "Yes"){
			$user = JFactory::getUser();			
			$row =& JTable::getInstance("chronoforms_UserWBtabel", "Table");
			srand((double)microtime()*10000);
			$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
			JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
			JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
			JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
			JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
			$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );			
			if (!$row->bind( $post )) {
				JError::raiseWarning(100, $row->getError());
			}				
			if (!$row->store()) {
				JError::raiseWarning(100, $row->getError());
			}
			$MyForm->tablerow["jos_chronoforms_UserWBtabel"] = $row;
		}
		?>
		<?php
		$MyForm =& CFChronoForm::getInstance("wb0");
		if($MyForm->formparams("dbconnection") == "Yes"){
			$user = JFactory::getUser();			
			$row =& JTable::getInstance("chronoforms_wb0", "Table");
			srand((double)microtime()*10000);
			$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
			JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
			JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
			JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
			JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
			$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );			
			if (!$row->bind( $post )) {
				JError::raiseWarning(100, $row->getError());
			}				
			if (!$row->store()) {
				JError::raiseWarning(100, $row->getError());
			}
			$MyForm->tablerow["jos_chronoforms_wb0"] = $row;
		}
		?>
		


Only table jos_chronoforms_wb0 is updated, not jos_chronoforms_UserWBtabel. So what's missing?
GreyHead 17 Aug, 2010
Hi Grover002,

Impossible to say from here. The data will save provided that ChronoForms has stored the updated table structure and some of the form input names match column names in the table.

Bob

NB You need to refresh the DB Connection after any changes to database column names. In the Form Editor click the DB Connection tab and set the Connection to 'No'. Click the 'Apply icon in the toolbar to save the form, open the DB Connection tab, set the Connection back to 'Yes' and re-save the form. This will refresh the copy of the table information that ChronoForms uses.
Grover002 17 Aug, 2010
Doesn't help. Tried the DBconnection trick, but no result. Form simply has this extra hidden field "Werkblad" and the table only has this column "Werkblad" type varchar(255), but it stores nothing, not even the chronoform fields like cf_id.
GreyHead 17 Aug, 2010
Hi Grover002,

By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.

Bob
Grover002 17 Aug, 2010
Can't point out how, but somehow it now works. Tried several things including switching of profile page and switching on again, and now both tables get updated!

Thanks for your assistance. Hope I can repeat this process for other forms ;-)

Bas.
This topic is locked and no more replies can be posted.