Custom forms Select field required


(Greig Fratus) #1

Hi,

 

I am developing a custom form in Matrix v3.28.2 to use as an online enquiry form. I have a select field which allows users to select an enquiry type, which is then emailed out according to the selection made.

 

My problem is that the select field wants a default option, which I do not want to give as users will just let that option be the one all of the time and I am trying to farm out the options. Nor do I want a series of radio buttons all over the form. I would like to have something like "please select" prompting the user to then use the drop-down to select an enquiry type but, if they do not, have them receive an error message and not be able to submit the form.

 

One way I thought of to get around this was to use a text field with a default of "please select", compare the two and send off an error message if they matched. The problem with this, however, is that I can't work out how to hide the text field so the user does not actually see it but it stiil is there to trigger the error message.

 

Any suggestions/ideas/experiences to share?

 

Thanks,

Greig


(Nic Hubbard) #2

Any suggestions/ideas/experiences to share?

 

Sure, this isn't too hard. Just use a normal select field and add a default option of something like "Choose one" or whatever you want. Then, create a new validation rule using a Regular Expression. Set the operator to NOT match. Then enter the text you used for your default option. 

 

Then, if the user tries to submit the form with the default option, it will throw the error with whatever text you want.


(Greig Fratus) #3

Hi Nic,

 

Thanks for the reply. The only problem is that the only option I have on the Select question for "Add Rule" is "Selection Limit". I can use the NOT match on a text field, which I have done, but I can't hide the text field so it looks a bit odd on the page. Any suggestions for how to hide a text field?

 

Cheers,

Greig


(Nic Hubbard) #4

Hi Nic,

 

Thanks for the reply. The only problem is that the only option I have on the Select question for "Add Rule" is "Selection Limit". I can use the NOT match on a text field, which I have done, but I can't hide the text field so it looks a bit odd on the page. Any suggestions for how to hide a text field?

 

Cheers,

Greig

 

That rule must have been introduced in a newer version, I am on 4.12.3.

 

Why are you needing to hide a text field?


(Greig Fratus) #5

Hi Nic,

 

I am using the validation, as you suggested, but on the text field. The text field has a default value that is equal to the default value on the Select field. This means that when the user is presented with the form the text field and the Select field have the same value. I have a rule on the text field that says that if the text field equals the Select field invoke the error message. This only works if the text field is on the form. Therefore I want the text field on the form but hidden so as to trigger this comparison and the error message if nothing has been chosen in the select field!

 

I hope that is clear!


(Greig Fratus) #6

I have an update on this issue. I have found the code that hides the text field for me (I am hiding the text field that I am using to check that an option has been selected in the Select field). The code is from http://forums.squizsuite.net/index.php?showtopic=6636. An issue I have subsequently come across, however, is that "

HTML contents of this container interfere with the edit interface. HTML parsing has been temporarily disabled. Below is the raw HTML content.". This does not seem to be affecting the use of the form under my quite limited testing.
 
Instead of putting in %question_field_<section_id>_<question_id>% I put in HTML code "<input type="hidden" value=sometext name="question_field_<section_id>_<question_id>" />"
 
Greig

(Nic Hubbard) #7

 

HTML contents of this container interfere with the edit interface. HTML parsing has been temporarily disabled. Below is the raw HTML content.". This does not seem to be affecting the use of the form under my quite limited testing.

 

 

Yeah, that is an ok error to see.


(Greig Fratus) #8

Thanks for the reassurance Nic!