Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Validate Subquestions?

Validate Subquestions? 4 years 2 months ago #82428

  • iwebkat
  • iwebkat's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 11
  • Karma: 0
I have used multiple short answers for a section including gathering name, email, phone, etc. Is there a way to add validation to these individual subquestions? I know regular expressions can be used for email addresses, zip codes, and phone numbers, but I haven't found a way to implement this.

I have been searching the manual, and have found the regular expression codes, but cannot find where exactly to put them to make them work.

Any pointers would be greatly appreciated. Thanks in advance!
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82431

  • ResearchOnBlogs
  • ResearchOnBlogs's Avatar
  • Offline
  • Gold Lime
  • Posts: 184
  • Thank you received: 16
  • Karma: 8
as far as I know it's not possible. I would use single questions.

research on BLOGS - Professional LimeSurvey support
Consultant - Templates - Training - JQuery magic - Support - Coding - Survey creation and more..

Contact
Professional LimeSurvey support
This email address is being protected from spambots. You need JavaScript enabled to view it.
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82433

  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5109
  • Thank you received: 756
  • Karma: 227
I read somewhere, that this option exists in the newest version, but I can't really tell how this works.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82434

  • iwebkat
  • iwebkat's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 11
  • Karma: 0
Thanks...if I can't figure out the sub-question route then I'll definite do this. It's nice to know it just isn't there.
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82435

  • iwebkat
  • iwebkat's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 11
  • Karma: 0
I just upgraded to the newest version, but I can't see where to validate subquestions. If you have any idea where to point me, I'll be happy to try.

Thanks!
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82436

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
The optimal way to validate sub-questions has not been implemented. Ideally, there would be a regex validation equation per sub-question so you could have different ones for each part of a multiple-short text. That doesn't exist yet (and probably won't for quite a while unless you know of volunteers with time to implement it).

However, you can fake it using the Whole question validation and Tip for whole question validation options.

Here is a working example.

File Attachment:

File Name: validate_s...ions.lss
File Size:21 KB


Say your question is "q1", and your sub-questions are "name", "email", and "phone", you could set the Whole question validation to:
(is_empty(q1_email) or regexMatch('/(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/', q1_email))
 and 
(is_empty(q1_phone) or regexMatch('/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/', q1_phone))

This will ensure that the user enters a valid email and phone number (in this case, a non-answer is also accepted via is_empty()).

Then, to tailor the validation message, you would use this for the Tip for whole question validation.
{if((is_empty(q1_email) or regexMatch('/(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/', q1_email)), '', 'Please enter a valid email address.<br />')}
{if((is_empty(q1_phone) or regexMatch('/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/', q1_phone)), '', 'Please enter a valid phone number.')}

As you can see, you are using the exact same validation expression for q1_email and q1_phone, you're just surrounding it with:
{if(validation_expression,'','Please enter a valid ....')}

And here are some screen shots:







Last Edit: 4 years 2 months ago by TMSWhite.
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82491

Hello TMSWhite, Got it!! For the others with same issue. Go to question. Go to advanced settings. Fill in the validation in 'Question validation equation' and the tip in 'Question validation tip'. The tip validates the same and shows the error message. q1 is your question code and email is sub question code. Good luck. And thanks TMSWhite.
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82492

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5984
  • Thank you received: 368
  • Karma: 260
janwillem64 wrote:
Hello TMSWhite, Got it!! For the others with same issue. Go to question. Go to advanced settings. Fill in the validation in 'Question validation equation' and the tip in 'Question validation tip'. The tip validates the same and shows the error message. q1 is your question code and email is sub question code. Good luck. And thanks TMSWhite.
Please add a note to the manual as well so other benefit from the findings, too.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Validate Subquestions? 4 years 2 months ago #82505

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
I've updated the manual here.
The administrator has disabled public write access.

Validate Subquestions? 4 years 3 weeks ago #84340

  • debianese
  • debianese's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
Thanks! This topic has helped me a lot!

But I have another question: How can you localize the error message?
I have to create a survey in german and english. The error message should be in the selected language!
The administrator has disabled public write access.

Validate Subquestions? 4 years 3 weeks ago #84342

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
For 1.92, you can do this:
{if(validation_expression,'',if(LANG=='en','Please enter a valid ....','Bitte antworten ...'))}

For 2.0, I'd recommend making this field one of those that can be translated into multiple languages via the quick translation feature.
Last Edit: 4 years 3 weeks ago by TMSWhite.
The administrator has disabled public write access.

Validate Subquestions? 4 years 3 weeks ago #84367

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9305
  • Thank you received: 1330
  • Karma: 386
Hello,

Can use pseudo class lang too in template.css:
<span lang="en">'Please enter </span><span lang="de">Bitte antworten</span>

And in template.css
:lang(en) :lang(de){display:none}
:lang(de) :lang(en){display:none}

Denis
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
Last Edit: 4 years 3 weeks ago by DenisChenu. Reason: typo and code
The administrator has disabled public write access.

Validate Subquestions? 3 years 11 months ago #85375

  • Bitbull
  • Bitbull's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Sorry to dig up this (old) thread, but I've got a serious problem with validation of subquestions. I've attached my survey here (sorry, it's in Dutch, but easy to understand as I've stripped it down to the problematic question).
I really don't see why I can't get past the question (when testing the whole survey, that seems to be impossible, a message keeps popping up). Regular expressions have been validated, everything seems fine with "realtime validation", but impossible to get past the question.
Could you guys please take a look and tell me what I'm doing wrong?
Thanks in advance!
Attachments:
The administrator has disabled public write access.

Validate Subquestions? 3 years 11 months ago #85442

  • Bitbull
  • Bitbull's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Okay, I already found the solution.
Apparently, regular expressions in LimeSurvey need to start & end with / character.
It was possible to notice in the example, but I found it nowhere clearly stated, only here (point 2)
The administrator has disabled public write access.

Validate Subquestions? 3 years 11 months ago #85482

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5984
  • Thank you received: 368
  • Karma: 260
If you are missing this information at our manual, please add it there. It's a wiki, everyone can edit it.

You can also post a feature request at our idea tracker to add some JavaScript validation before saving a regular expression. Such a script can check for the first characters and throw an error.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.373 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form