• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Validation - check across answers

Validation - check across answers 10 years 7 months ago #28808

  • clucking
  • clucking's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Thank you received: 2
Hi,

I hope one of you can help me - unfortunately I'm not familiar with PHP but I think this is not very complex:

I have a number of questions in my form - let's say 4. I want the answers to be ranked / prioritised.

I think of having 4 radio buttons for each - given the values from 1 to 4. I know how to handle this. But I want to check every time a user sets a value for a question that this value has not been set for any other question. In this way, one question will get value 1 - another value 2 and so on.

I guess I have to write a validation in the PHP section of the form - but as I said - I have a huge lack of php knowledge...

Anyone?

thanks!

Claus.
The administrator has disabled public write access.

Validation - check across answers 10 years 7 months ago #28829

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
You can approach this with the use of Javascript, create a code that checks the value of the radio buttons for duplicates and block the submit button if found.
  1. Create 4 radio groups, for this example I will name them : "one", "two", "three" and "four" , and in the Additional Attributes area of all of them add : onclick="duplicate();" (this is the trigger for the function you will create in the Javascript section);
  2. Edit the submit button and in the Additional Attribute area insert : disabled="true";
  3. Head over to CSS and Javascript section and insert the following code:

<script>
function duplicate(){
 
var checked = [];
 
var i;
for(i=0;i<document.getElementsByName('form[one]').length;i++)
if (document.getElementById('one'+i).checked){
var one = document.getElementById('one'+i).value;
checked.push(one);
}
 
var j;
for(j=0;j<document.getElementsByName('form[two]').length;j++)
if (document.getElementById('two'+j).checked){
var two = document.getElementById('two'+j).value;
checked.push(two);
}
 
var k;
for(k=0;k<document.getElementsByName('form[three]').length;k++)
if (document.getElementById('three'+k).checked){
var three = document.getElementById('three'+k).value;
checked.push(three);
}
 
var l;
for(l=0;l<document.getElementsByName('form[four]').length;l++)
if (document.getElementById('four'+l).checked){
var four = document.getElementById('four'+l).value;
checked.push(four);
}
 
var arr = [one, two, three, four];
var sorted_arr = arr.sort(); 
 
var results = [];
for (var h = 0; h < arr.length - 1; h++) {
    if (sorted_arr[h + 1] == sorted_arr[h]) {
        results.push(sorted_arr[h]);
    }
}
if (results.length > 0)
	document.getElementById('Submit').disabled = true;
 
else if (checked.length == 4)
	document.getElementById('Submit').disabled = false;
}
</script>

Please keep in mind to edit the code so it reflects your fields specific id's and names.

More information on Javascript can be found here:
http://www.rsjoomla.com/support/documentation/view-article/481-css-and-javascript.html

PS: The above code is merely an example and not a solution.
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
The following user(s) said Thank You: clucking

Validation - check across answers 10 years 7 months ago #28838

  • clucking
  • clucking's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Thank you received: 2
It works just perfect...
I really appreciate your answer!
Thanks from a java script / php non programmer :)

Claus.
The administrator has disabled public write access.

Validation - check across answers 10 years 7 months ago #28910

  • clucking
  • clucking's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 21
  • Thank you received: 2
Cosmin.cristea - as described it is working great but could I ask you to extend the code a little bit?

I need to devide my questions into two groups each having a number of answers. Lets say one group which is equal to the solution as it is now - and another new group with three similar questions. The behavior of the second group should be equal to the first one - the user again must set answer one, two and three for the questions in this group in order to have the submit button active. Again answers must be different for the three new questions.
In this way overall there will be to answers for one, two answers for two and three answers for value three. But only one for four since it is only present in the first group of questions.

Thanks again - I really appreciate if you can help me one more time!

Best regards,

Claus.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!