Pulling data into a form

mazzy 28 Feb, 2010
Let me preface my question with my scenario. I am using the Multi Page plugin to save form data from 2 forms to a single database which works perfectly! I have Form A setup as the registration form using the Joomla Registration plugin since I have a couple of extra fields. Form B is only accessible after user has logged in.

My question is how do I get information from Form A to display in Form B? The following are the details:

Form A captures:
Company Name
Name
Phone Number
Email/Username
Password

The top section on Form B needs to display:
Company Name
Name
Phone Number
Email/Username

The rest of From B will be filled out by the user and will ammend the new data to the database.

The following is the code I am using (unsuccessfully) at the beginning of Form B per Bob's direction 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>


I've looked through the forum extensivly but haven't been able to piece a solution together, so any help would be greatly appreciated!

I also need some clarification as to how to send delayed emails. I have three seperate emails setup:
Email #1 - sent out after Form B is submitted
Email #2 - 50 days later
Email #3 - 60 days later

Thanks for your help!
GreyHead 28 Feb, 2010
Hi Mazzy,

You will need to put the correct table name in #__chronoforms_formname

Delayed emails are probably possible but you will need some code to trigger them. Neither Joomla nor ChronoForms have any sense of time.

You can though trigger a Cron job from your server to run a php file (possible a form) that will check if any emails are due and send them.

Bob
mazzy 28 Feb, 2010
Hi Bob,

Thanks for the quick response! I should have said that I do have the correct table name, it's #__chronoforms_adminreg, but I'm still not getting any fields displayed. I'll also mention that I have cf_id set as the primary key if that helps.

I'm not very php saavy so if you or anyone could point me in the right direction as to how I can setup a php file (or a form as you mentioned) that would run the email delay, it would be extremely helpful.

If you need more information please let me know, thanks!
GreyHead 28 Feb, 2010
Hi Mazzy,

Hard to say - there's nothing in the HTML you posted that would show anything.

Bob
nml375 28 Feb, 2010
Hi Mazzy,
Although depending on how you've set up your database connections, usually all the collected data is stored once when the form is completed, any data collected will be kept in the session object until then.

I don't remember if the stored data would be availabe through CF's $posted array, but you should always be able to get them from the session storage. I don't have the exact code in front of me right now, but I'll look it up in the evening.

/Fredrik
mazzy 28 Feb, 2010
Thanks Bob for all your help😀

Fredrik, looking forward to your post. Is it because I'm using the Multi Page setup that the curent code isn't working? I'm also going to poke around the forum some more to see if I can find another example of session storage. If you need a .cfbak or access to the site, I'd be more than happy to provide it.

Does anyone have any suggestions as to how to setup the email delay?

Thanks again!
nml375 28 Feb, 2010
Hi Mazzy,
If you've set up the DB Connection in the mother form (as recommended), this is indeed why the code does not work as intended (data is not stored in the database until the whole form is completed/submitted).

To access the already submitted, but not yet stored data, use the following code:
<?
/* First of all, we need our session object */
$session =& JFactory::getSession();

/* Next, we'll have to fetch whatever is stored
 * within the session object, and save this to
 * a new variable. I'll use $tmp_data here.
 * Also, we have the opportunity to provide some
 * default data, if there is no data available;
 * I'll use array() to return an empty array in
 * this case, as we'd expect array data anyway.
 * Also remember to change the 'motherform' part
 * to match whatever you named your motherform.
 */
$tmp_data =& $session->get('chrono_formpages_data_motherform', array(), md5('chrono'));
?>
...
Company Name: <?
/* Now to print the data; here I assume we called
 * the Company Name form input 'company_name'.
 * I also assume that the data is available, you
 * could fairly easily add a check for a value,
 * and/or provide a default value if needed.
 */
echo $tmp_data['company_name'] ?>
....


Regarding delayed emails, as Bob said, you can use a cronjob for this - if available. Many hosters do provide means to call a website on given intervals, through their control panel, CPanel, etc. This would then have to point to a php-script, or perhaps the extra-task of your chronoform. This script/form would then be responsible to retrieve a list of emails that are yet to be sent, check their due-date; and if expired, send them accordingly. Best would probably be to use a database table for this list of emails.
There might be some components or plugins out there that already provide this feature, but you'll still need some means of triggering it all. Some approaches try to hook in whenever someone visits the site, though for obvious reasons this is a rather unreliable approach unless you have a very steady stream of visitors/hits.

/Fredrik
mazzy 28 Feb, 2010
Fredrik,

Thanks very much, I will try your new code when I get back later. I will let you know my results, though I'm sure this is what the missing piece if the puzzle is!

I will also look around as you suggested for a component or plugin in regards to the delayed email function, or at least an existing php script that I can use.

You guys are fantastic!!
mazzy 01 Mar, 2010
Fredrik/Bob,

I placed the code in the appropriate area and it does indeed pass the information from Form A to Form B. The problem I am now running into though is once Form A (registration form using Joomla registration plugin) is filled out and the user logs in and fills out Form B, none of the information is getting posted to the database.

Thanks!
nml375 01 Mar, 2010
Hi,
That is very odd...
Simply reading the session data should not damage it, or prevent the forms from storing the data.

Would you be comfortable making a backup of your current forms, and attach them here?

/Fredrik
GreyHead 01 Mar, 2010
Hi Fredrik & Mazza,

It's possible that logging in refreshes the session and loses the data :-(

It might work if the user completes Form B without logging in ??? You can check the User Object to make sure that it's the right person.

Bob
mazzy 01 Mar, 2010
Fredrik,

I have PM'ed you with the cfbak files. Please let me know if you need anything further, thanks!
nml375 01 Mar, 2010
Mazzy,
Thanks. Having a look now..
I notice you've set up DB Connection for both your child forms and your mother form. I wonder if this is what is causing your problems.. Usually, you would only add the DB Connection to the mother form, having the data saved once the last step is completed.

Also, you re-define the $posted array with $session->get('chrono_formpages_data', array(), md5('chrono')) - this would always be the empty array since that session value would never get stored in the first place. The $tmp_data is properly defined though..

I'm not sure if this is working, since $data is not defined in the second form:
<input type='hidden' name='cf_id' value='<?php echo $data->cf_id; ?>' />

Also, this is only needed since you've enabled DB Connection in both child forms as well as the mother form.

I also see you do your emailing in the second child form, rather than in the mother form.

..
After a little tweaking, I got your form backup up'n'running. The first thing I notice, is that I get three different records for each submission. This is because of the incorrect cf_id hidden input and the multiple DB Connections.
Disabling the DB Connection in the child forms and only keeping the one in the mother form solved this for me, and removed the need for any hidde cf_id fields.

/Fredrik
mazzy 01 Mar, 2010
Fredrik,

I made the suggestions per your post above. I think the issue that is throwing things off a bit is that after Form A (registration) is submitted, the user will not be taken directly to Form B. They will need to login first and then they will have access to Form B. When I implemented your changes, everything moves along fine but there is no data being saved to the database once Form B is submitted. Meaning, no data at all is pushed to the database😟 I'm sure I've overlooked something, should I have anything in the 'Finalize button name' and/or should I have 'Steps navigation' enabled? Thanks again!
nml375 01 Mar, 2010
Ahhh, then I see...
If you need your user to manually login between steps, then I'm not sure the Multi Page plugin is what you need. Instead, simply use the two separate forms, possibly using the Profile plugin in the second form to load the stored data conveniently, or simply by using an SQL-query.

I don't suppose the "Auto login" option in the Joomla Registration plugin could be used to avoid the middle "step" of user manually logging in, in order to continue?

/Fredrik
mazzy 01 Mar, 2010
Fredrik,

Thanks for the quick response🙂 I'll change it from a multi page to two separate forms, but I'm unsure what SQL query needs to be used to dispaly info from Form A to Form B with a login in between and then have it post to db as a single entry.

I can't do auto login unfortunately and I don't think the Profile plugin will work because I need to dispaly two extra fields that Joomla doesn't handle:

Form A (registration) data to reflect in Form B (after user is logged in):
Company Name
Name
Phone
Email/username

I really appreciate all your help!
nml375 01 Mar, 2010
Mazzy,
The point of the Profile plugin is simply to retrieve one row of data from a database table, and insert it into the generated form. In this case, you'd tell it to retrieve data from your jos_chronoforms_adminreg table, and use cf_user_id as the "target field name". Leaving both "Request parameter name" and "Default Request parameter value" empty will make the plugin use the currently logged in user's id as the value to look for.

All you need to do then, is insert {fieldname} wherever you'd like the value of the corresponding fieldname into your form. If you make sure to include the cf_id hidden input <input type="hidden" name="cf_id" value="{cf_id}" /> the normal DB Connection will update the old post in favor of creating a new one.

/Fredrik
mazzy 01 Mar, 2010
OMG! that is exactly what I was looking for! Thank you Fredrik and Bob for all the wonderful help you've provided, I REALLY appreciate it 😀
This topic is locked and no more replies can be posted.