Forums

Update DB with data from second form

mazzy 26 Feb, 2010
Hello all,

First off, this is an excellent component and extremely powerful. Tried it out at first to make sure it would work for a particular project and decided to purchase a 3 domain subscription.

I've looked through extensively on the forums and though I found several topics similar to my problem I'm having trouble tying them all together. I'm new to chronoforms and don't have much experience with php or mysql so that probably is why I'm a bit lost.

The issue at hand is as follows:
I have a registration form that is using the Joomla Registration plugin with data being saved to "jos_chronoforms_formname" since I have two extra fields (Company Name and Phone) that are not part of the normal joomla registration. Everything works perfect there, user is registered and able to login and data is sent to "formname" database.

The second part is where the issue occurs. Once user is logged in they are taken directly to a new form that expands on their information. I want to be able to update the "jos_chronoforms_formname" with this new information. I have both Form A and Form B connected to the "jos_chronoforms_formname" table per your tutorial, but beyond that I'm completely stuck.

Aside from that I am also having trouble pulling the information from Form A into Form B so that it is displayed but uneditable, for example:
Form A:
Company Name
Name
Phone Number
Email/Username
Password

Certain data needs to be passed on to Form B: (once logged in)
Company Name
Name
Phone Number
Email/Username

I've seen lot's of references to getUser but I just can't put it all together. I've also tried the profile plugin but it seems will only work if the userid is known. I know the answer lies somewhere just a little beyond my reach.

I have cfbkup files ready if needed. I am grateful for any guidance, thanks!
GreyHead 27 Feb, 2010
Hi Mazzy,

For Form B you must make sure that the 'primary key' for the user is included in the form html in a hidden field. Which column is the primary key will depend on how you set up the table - ideally it would be a column with the user_id in it. If you used the ChronoForms Create Table then it's probably cf_id but you could still change it to cf_user_id.

You can get the Form A data by including a MySQL query at the beginning of Form B.
<?php
if ( !$mainframe->isSite() ) { return; }
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
  SELECT *
    FROM `#__chronoforms_formname`
    WHERE `cf_user_id` = ".$user->id." ;
";
$db->setQuery($query);
$user_info = $db->loadObject();
?>
. . .
<input type='hidden' name='cf_id' value='".<?php echo $user_info->cf_id."' />

Bob

PS You could also use the Multi-part plugin to link the two forms together - that requires slightly different code to access the previous data.
mazzy 27 Feb, 2010
Hi Bob,

I copied the code you supplied above into the beginning area of the Form HTML and am receiving the following error code:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in path_to\components\com_chronocontact\chronocontact.html.php(180) : eval()'d code on line 16


I will send the cfbak files to help the process. Thanks for all your help.
GreyHead 27 Feb, 2010
Hi Mazzy,

What is in line 16 of the form html (with a few lines either side please)?

Bob
mazzy 27 Feb, 2010
Hi Bob,

The following are lines 12 through 19 on the chronocontact.html.php file:

/* ensuring that this file is called up from another file */
defined('_JEXEC') or die('Restricted access');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

class HTML_ChronoContact {


Thanks!
mazzy 27 Feb, 2010
I have isolated the error having to do something with the hidden field code:

<input type='hidden' name='cf_id' value='".<?php echo $user_info->cf_id."' />

When I remove it from the code the form shows up with no errors, but it's also not pulling in any information from Form A. I'm looking around the forum to see if I can find the answer, but if anyone can help I'd really appreciate it, thanks!

*EDIT*

I corrected the hidden field code per another post's example to:

<input type='hidden' name='cf_id' value='<?php echo $user_info->cf_id; ?>' />

The form page now shows without error BUT still not pulling in information from Form A. I'm also still unsure as to how to ammend the existing DB with the new information gathered from Form B. Any help would be much appreciated!
mazzy 27 Feb, 2010
I figured out how to use the MultiPage plugin to capture data from Form A and Form B and have it saved to a single Database! So now all that's left is to pull data from Form A into Form B once the user has logged in. Again just for quick reference the following is the code I am using at the beginning of Form B per Bob's direction (with the hidden field correction) and a bit of the form code itself for good measure.

<?php
if ( !$mainframe->isSite() ) { return; }
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
  SELECT *
    FROM `#__chronoforms_formname`
    WHERE `cf_user_id` = ".$user->id." ;
";
$db->setQuery($query);
$user_info = $db->loadObject();
?>

<input type='hidden' name='cf_id' value='<?php echo $user_info->cf_id; ?>' />
. . .

<div class="form_item">
  <div class="form_element cf_textbox"><label class="cf_label" style="width: 150px;">Company Name*</label>
  </div>
    <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox"><label class="cf_label" style="width: 150px;">Name*</label>
  </div>
 <div class="cfclear"> </div>
</div>

Thanks for any light that can be shed on this!
This topic is locked and no more replies can be posted.