Referencing Form Question asset attributes in keywords


(*) #1

Within a Page Contents area within a form, you get access to a preset group of keywords relating to the ID, name, note, etc for Form Questions, such as:

  %question_id_12345_q1%
  %question_name_12345_q1%
  %question_note_12345_q1%
  %question_error_12345_q1%

What doesn’t appear to be working is the generalised attribute access to the attributes (or any keyword for that matter) of a Form Question.

For starters, we can get access to the Asset ID of the question thus:

%question_id_12345_q1%  (produces "q12345_q1")

and thus you’d expect that using this asset ID one would be able to be used to access/refer to keywords/attributes/etc from that asset. For instance, in any of the following ways:

%globals_asset_attribute_extra:q12345_q1% (is blank)
%globals_asset_attribute_is_required:q12345_q1% (is blank)
%globals_asset_name:q12345_q1% (as a test, is blank)
%globals_asset_name:12345:q1% (the "12345:q1" is ID the asset map shows; is blank)
%question_id_367113_q1^as_asset:asset_name%  (a simple test; is blank)

you end up with blank output. In the first cases, hard-coding the asset ID don’t appear to work and neither does a keyword modifier. The final example is contrived (I know that the simpler %question_name...% exists), but it should seemingly still work to prove that access to other keywords would too.

Essentially, I’d like to refer to any of the keywords and attributes associated with the Form Question so I can use them in any asset on Matrix – or at very least, in the Page Contents of a customised Form.

Is this possible? Is there another form of keyword to get

Tests above were performed in Matrix v5.3.3.0.


(Bart Banda) #2

Questions aren’t physical assets, they are shadow assets off their form contents/sections parents. So they are really part of that asset ID.

There are also limited values you can get from these questions as I think most of the data is stored as a serialised PHP array on the DB.

We could potentially look at developing new keywords for any new attributes that would be useful.

Just out of curiosity though, what is the use case here? Are you trying to use form field data from a custom from asset in a different asset context?

Form field keywords are only meant to work and be used within the Custom Form asset they are children of.


(*) #3

I’m attempting to build my own form within the Form Content’s ‘Page Contents’ asset. At present, I can get some key information (ID, name, note, error, label), but other attributes of a Form Question (is required, placeholder, width, height, type, extras, etc) aren’t available for use in constructing the form.

Having individual keywords for everything would solve the issue, as long as there’s a keyword for each attribute. However it seems simpler if the pre-existing keyword format for attribute access were extended to work on these ‘shadow’ assets.

Either way, that requires both implementation on your side and then eventually an upgrade on ours – making lead time a long time away. In the meantime, the simplest solution is just to hard-code it all into the Page Contents asset. That’s not such an bad solution because I’m already having to hardcode the field order, asset IDs in keywords etc; but I’d still prefer just one location (eg the Form Questions) where an editor can make changes and avoid touching the HTML.


(Bart Banda) #4

I think your best option is to then just use the %question_field_<parent_id>_<question_id>% keywords as it will automatically output all the extra attributes that are assigned to the field in the backend by editors.

Doing this you can still add your own custom markup using the replace keyword modifier. For example, if you want to add another custom attribute:

%question_field_<parent_id>_<question_id>^replace:/>: data-custom="foo"/>%


(*) #5

Thanks for the suggestion.

I suppose I could use logic like ^contains:required to do some string manipulation but the simpler option is just to hand-code the HTML. That’ll make it less messy and simplify understanding for later maintenance.