Forums

Populating a form from previously submitted data

deltronzero 11 Mar, 2009
At present, I have a form which the users from my site fill in and once submitted, it gets saved to my db chronoforms_ce. The forms contains the user name and 10 other bits of information selected from drop down boxes.

What i would like to do now, is create a duplicate of this form that displays the users previously submitted data based on their username. This form will be read only and its purpose is to serve as a reminder for the user to see what they have submitted.

I have used my previous code to get the username of the person, but i'm not sure of the next step:
<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>
<div class="form_item">
   <div class="form_element cf_textbox">
      <label class="cf_label" for="name">Name:</label>
      <input type="text" readonly="readonly" name="name" id="name" size="20"
maxlength="40" value="<?= $user->name; ?>" />
   </div>


The next step would be to populate text box 1 with the information submitted by the user in combo box 1, that is stored in the db. I think the code below could be used with some modification (replacing the x's):
<DIV class=form_item   >
<DIV class="form_element cf_textbox" ><LABEL class=cf_label >Selection 1</LABEL>
    <?php
    $db =& JFactory::getDBO();
    $query = "
      SELECT *
        FROM #__chronoforms_ce ";
    $db->setQuery($query) WHERE xxxxx;
    $rows = $db->loadResultArray(xxxx);
    ?>
   
x
x
x
x
   
</DIV>


Any help would be greatly appreciated
nml375 11 Mar, 2009
Any thoughts of using the Profile Page plugin for this?
deltronzero 11 Mar, 2009

Any thoughts of using the Profile Page plugin for this?



can you explain this a little further?
nml375 12 Mar, 2009
Sure, the Profile (chronoforms) plugin is a nifty helper that, once setup properly, allows you to retrieve data from a table and easily insert it into your form.
I believe there are numerous threads covering this on the forum, so a search might provide further information.
But simply put though, create your form as usual, except write {fieldname} wherever you wish to insert the corresponding field value from your database table into the form.
Also, on the Plugins tab, you'll need to check the box for the "Profile" plugin.

Then check the box next to your form, and click the "Profile Page" link on the left. This allows you to setup which table to retrieve data from, what table field should be search'd for the proper row, and how you pass your search parameters to the form.

Finally, to view your form with inserted data, visit http://somehost/yourform?id=13 (SEF and menu link) or http://somehost/index.php?option=com_chronocontact&chronoformname=yourform&id=13 (if you don't use menu links) or similar.
You basically add one more parameter to the url, in this case I choose "id", to tell the plugin which row from the table to load.

Try and play around with it, since the Profile plugin only reads data, and doesn't alter anything in your database, at worst you'll end up with a form looking awful. And just drop a question if you get stuck anywhere in the process.
deltronzero 12 Mar, 2009
I've had a bit of a play and a search on the forums and am still having a little trouble with this.

I have linked my new form to the db populated from my other form with the target field set to name, as this is what i want to check against each of the values when displaying:

i.e. i want to check the JB user name against the user name in my db and if they match, display the value in field x.

I am now stuck on displaying the data i want in a text box. I have tried numerous SQL statements, but i cant get it to work.
Max_admin 12 Mar, 2009
Hi,

JB user = ??

please post a screenshot for your plugins tab and the profile plugin config page and it will be much easier to find whats missing!


Cheers,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
orubin 03 Jul, 2009
(Deleted and post moved to new topic "Using Profile Plugin to populate a form".)
This topic is locked and no more replies can be posted.