Pulling data from one form into another to place in the middle of static text

Status
Not open for further replies.

degarrin

Member
Here is what I want to do...

I have two forms - Form A and Form B. Form A is always filled out before Form B. Form B is a text-heavy form, but it also has fields that are a combination of text and information that is pre-populated from Form A; I need to insert information in the middle of existing text. Here is a sampling of text from one such field in Form B:

"{fab_affirmations___partner_names} and {fab_affirmations___client_id}, I remind you that a sacred union is a precious gift, a commitment, and a challenge to love one another more completely each and every new day. Please join hands and look into each other's eyes and recite your vows."


Right now, the text-heavy fields (such as the sample above) are just display fields because there is nothing to edit. But I cannot think of a way to get this to work or if this is even possible. I know that outputting the text-heavy fields as an email/PDF/Joomla article directly from Form A works because I've tried, but that is not what my church wants, they need it as a separate form with additional information.

I tried autofill, where I put the fields on Form A (as hidden) and then duplicated them on Form B, but that did not pull over the placeholder data. I suspect because you can't use placeholders from one table when autofilling data into another table? I know placeholders only work with their own table, but I was hoping autofill might get around that - guessing not...

Then I thought that there may be some way to do this with eval'd code on each element, calling to the other table, but when I played around a bit it just puts the text below my display text. I'm not very experienced with the PHP code calling from one table to another though, so I may have gotten something wrong.

Does anyone have some suggestions? Any thoughts are appreciated, as I'm kind of at the hair pulling stage on this one.

Thank You
Angela
 
How are the two forms related?

In other words, do you have something like a join on form2 which point to the related form1?

-- hugh
 
Form 2 has a databasejoin element called "fab_affirmations_ritual___service_id" that points to Form 1's ID element; it's a hidden element. Then in Form 1 I have related data for Form 2 with "Link to List = Yes" and "Link to Form = Yes". On the frontend, users have list access only to Form 2, so they have to link it through a created Form 1. I attached an image file with the frontend view.

Would it have been better to do it another way?

Angela
 

Attachments

  • service_test_view.JPG
    service_test_view.JPG
    52.9 KB · Views: 213
Yes, you'll have to do it with some PHP in an eval'ed element default.

The problem with doing it in a display is that it doesn't get saved in the table on form submission, and relies on the &fab_affirmations_ritual___service_id=X being set in the query string (URL), which is how we do the "New" link with related data. We automatically add the rowid from the list as the FK (join in the second form pointing back at the first). But if you ever edit or view that form without coming from the first form's list, it won't be there.

Would a textarea in read only mode work?

In either case, the code would look like something like this:

Code:
$service_id = $this->app->input->get('fab_affirmations_ritual___service_id' ,'');
if (!empty($service_id)) {
   $myDb = FabrikWorker::getDbo();
   $myQuery = $myDb->getQuery(true);
   $myQuery
      ->select('s.partner_name, c.client_name')
      ->from('your_service_table AS s')
      ->join('LEFT', 'your_client_table AS c ON c.id = s.client_id
      ->where('id = ' . $myDb->quote($service_id));
   $myDb->setQuery($myQuery);
   $row = $myDb->loadObject();
   return "Partner is " . $row->partner_name . " blah blah client name is " . $row->client_name;
}
return "ooops";

Note that it looks like you have another table you may need to join, as you mention a client_id, so I added that in my example.

-- hugh
 
I hadn't thought of a read only text area element, I'll have to tinker with that. And I appreciate the code example a lot. Thanks Hugh!

Angela
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top