Hidden field issue

Hi everyone,


I have a form where one of the fields is a hidden field, and its value is derived from a URL query string.



I've used this code:



<input type=hidden value=%globals_get_offer% name=question_field_79361_q26>



When I look at the source code of the rendered page, the field code reads <input type=hidden value=offertext name=question_field_79361_q26> - where "offertext" is the correct query string.



I have another hidden field on this same form, with the code:



<input type=hidden value=sometext name=question_field_79361_q27>



Both fields are text fields.



When the form is submitted, only the second field's contents come through in the form submission, the first field remains blank.



Anyone have any idea why this might be happening? :unsure:



Cheers,



Ben

Is the first field nested within the same <form> tag as the second field? If this is not the case, your first term will not be submitted by the action associated with that form.

Are you using proper, valid tags with quotes? Or did the forums strip those?

[quote]
Is the first field nested within the same <form> tag as the second field? If this is not the case, your first term will not be submitted by the action associated with that form.

[/quote]

Hi Mark,



Yes, they are both part of the same form.


[quote]

Are you using proper, valid tags with quotes? Or did the forums strip those?

[/quote]

Hi Nic, yes they are valid tags. They weren't, since I had them in a WYSIWYG DIV and Matrix strips the quotes itself(!), but when I saw your post I put them in a raw HTML div on their own, and surrounded them with quotes, and the same behaviour continues. So the fields being validly or unvalidly marked up makes no difference.



I thought it might be because the query string had two components with an underscore, ie offer_variable, so I tried with a simplified one and no good.



Then I replaced the %global_get_offer% with plain text, and still no good. I am going to try a different field and see if I get the same result.

I was incorrect. The second field was merely reporting the default value of the field - I don't remember setting a default value, but there you go…


So neither of them are coming through. I've tried every variant I can think of, and still nothing. Bizarre…

[quote]
I was incorrect. The second field was merely reporting the default value of the field - I don't remember setting a default value, but there you go…



So neither of them are coming through. I've tried every variant I can think of, and still nothing. Bizarre…

[/quote]



How are you checking to see what values are being posted? Firebug or some other software?

[quote]
How are you checking to see what values are being posted? Firebug or some other software?

[/quote]

Actually, I was just seeing what appeared in Matrix's default %form_summary% keyword replacement when the form was submitted. But Firebug turned out to be a good suggestion, because it showed me that you can't use the keyword format to reference hidden fields: it looks like the field is being submitted in the same format as regular fields in the HTML, but it ain't…



So I played around with formats and eventually found that q<assetid>:q<question_number> was the one that works - ie for a form with the asset id 10000, question number 23, you would use the format:



<input type="hidden" value="test" name="q10000:q23">



I've got to say, it would be really helpful if information like this was in the Matrix Custom Form documentation. It's not like hidden fields are perversions of normal form use, and I don't think developers should have to use Firebug (and Nic) to find out how Matrix wants a hidden field formatted.



Anyway, once again, thanks Nic, and no, I don't regard you as my personal Matrix tutor :wink: - but you are definitely the most valuable forum contributor Squiz could hope for in their user base.

[quote]
So I played around with formats and eventually found that q<assetid>:q<question_number> was the one that works - ie for a form with the asset id 10000, question number 23, you would use the format:



<input type="hidden" value="test" name="q10000:q23">

[/quote]



What I have always done when I wanted a form to have a hidden field, was just create a normal text field, and preview the form with that keyword to see how Matrix prints the input tag. Then, just copy and paste that in, instead of the keyword, and change the input type to hidden rather than text. Works every time. :slight_smile:

[quote]
What I have always done when I wanted a form to have a hidden field, was just create a normal text field, and preview the form with that keyword to see how Matrix prints the input tag. Then, just copy and paste that in, instead of the keyword, and change the input type to hidden rather than text. Works every time. :slight_smile:

[/quote]



D'oh! :smiley:

Some other information to note as well. The asset id is the parent asset of the question. So a form with no sections will have the form contents asset id for all questions, however a form with sections will use the section asset for the asset id. All the tags should also have the id attribute which has the format of q<assetid>_q<question_number> which is a lifesaver if you are using your own javascript to highjack the form as well(Nic :))

[quote]
<input type=hidden value=%globals_get_offer% name=question_field_79361_q26>

[/quote]



Just tested, the hidden input works with the format like below,

    

The page content has to be fully customised with keywords of the question label and field.

Robin:rolleyes:

[quote]
Some other information to note as well. The asset id is the parent asset of the question. So a form with no sections will have the form contents asset id for all questions, however a form with sections will use the section asset for the asset id. All the tags should also have the id attribute which has the format of q<assetid>_q<question_number> which is a lifesaver if you are using your own javascript to highjack the form as well(Nic :))

[/quote]



I'm hijacking the forms almost as much as Nic would be, I think! :wink:



Yep, that's what I discovered. And it makes sense, sort of, once you've nutted it out.



I just reckon that info should be explicitly in the documentation, so each Matrix user doesn't have to come to this forum and discover this thread, or sit there testing different possibilities until they stumble across the right one, for what is a very common form operation. And then to have it not work if the form has different sections (and I assume a multipage form would add wrinkles again). It's very frustrating to have to spend a few hours working out what should be very, very basic stuff from first principles…