Is there a way in Matrix to pre-populate a form field with a metadata value from another page?
Basically we provide information on a page that is printed from metadata. We then allow users to link to a form to make a booking. Rather than the user having to complete the whole form we would like some of the details that were on the previous page to automatically populate the relevant form fields.
Users of 3.16.8+ can use keywords to access metadata from other assets, in the following format
%globals_asset_metadata_FIELDNAME:ASSETID%
If you're lucky, your system may have this functionality?
Thanks we're running 3.16.13 so that works fine, however is there a way to dynamically generate the asset id within that keyword rather than having to hardcode it?
What we are trying to acheive is:
- Generate an asset list that has a link to a form which passes the asset id of that asset list item as a url parameter
- Populate the keyword you provided based on the asset id parameter that has just been passed
- The form then uses the keyword to populate the relevant form fields
Is the above possible or is there another way?
Hey Bridgy,
If you don't mind using a bit of javascript then you should be able to do this fairly easily.
What we are trying to acheive is:
1. Generate an asset list that has a link to a form which passes the asset id of that asset list item as a url parameter
In your type format for the asset listing include <a href="./?a=assetidofform?id=%asset_assetid%">link name</a>
2. Populate the keyword you provided based on the asset id parameter that has just been passed
This is where you're going to have to get a liitle bit tricky with some javascript magic. You need to retrieve the GET parameter from the URL (which we thoughtfully called "id") so that you can reuse it in the rest of the page.
3. The form then uses the keyword to populate the relevant form fields
Once you've retrieved the asset id from the URL with your js, use the
%globals_asset_attribute_FIELDNAME:ASSETID%
%globals_asset_metadata_FIELDNAME:ASSETID%
keywords to add the values into the form fields.
I think that in 3.18 there is a global keyword which will retrieve any GET parameters without the need for JS, but I can't confirm that at the moment (anyone in Aus confirm?)
Hope this helps
Yes, this is correct. Although I can't remember which minor version it was added in.
3.18.3
OK so we have managed to pass the current asset ID and then get that value from the url.
The issue we have encountered is that when we try and place the asset id that was passed into the %globals_asset_metadata_FIELDNAME:ASSETID% keyword it prints the asset id on screen in the keyword e.g. %globals_asset_metadata_Field_Name:126254% rather than converting it to the metadata value.
Is this because the keyword does not like having the javascript within the kleyword e.g. %globals_asset_metadata_Field_Name:<script type="text/javascript">document.write(gup('id'));</script>%?
Does anyone know of another way to get this work?
[quote]OK so we have managed to pass the current asset ID and then get that value from the url.
The issue we have encountered is that when we try and place the asset id that was passed into the %globals_asset_metadata_FIELDNAME:ASSETID% keyword it prints the asset id on screen in the keyword e.g. %globals_asset_metadata_Field_Name:126254% rather than converting it to the metadata value.
Is this because the keyword does not like having the javascript within the kleyword e.g. %globals_asset_metadata_Field_Name:<script type="text/javascript">document.write(gup('id'));</script>%?
Does anyone know of another way to get this work?[/quote]
I would say yes, it does not like having the script tags, or document.write statement within a keyword, that just won't work. Also, keywords get replaced before any content gets printed, so sadly, this will never work using this method. 
edit: unfortunately can't delete my post…