• 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: Cannot have the same value as another field

Cannot have the same value as another field 1 month 3 weeks ago #43298

  • info4344
  • info4344's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Hello,
I read in the validation rules that you can set "same as another" field to compare if their value is identical. Can the contrary be done too?

I have two email fields "my email" and "my friend's email" and I'm unable to stop users from putting their email twice.

Is there a way to do that?
Kind regards
Lorenzo
The administrator has disabled public write access.

Cannot have the same value as another field 1 month 3 weeks ago #43299

  • dragos
  • dragos's Avatar
  • OFFLINE
  • Administrator
  • Posts: 559
  • Thank you received: 102
Hello,

You can try using something similar in your form > Form Properties > PHP Scripts > Script called on form process area:
if($_POST['form']['myEmail'] == $_POST['form']['myFriendsEmail'])
$invalid[] = RSFormProHelper::getComponentId("myFriendsEmail");

Make sure to replace 'myEmail' and 'myFriendsEmail' according to your actual field names.
The administrator has disabled public write access.
The following user(s) said Thank You: info4344

Cannot have the same value as another field 1 month 3 weeks ago #43312

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 216
  • Thank you received: 57
You can also do it with javascript, below is an example of a function I use to compare two fields, it shows an alert and emptys the second field if the entered content was the same as the first field. called in the Address2 field attributes with onchange="compare();"
//compare address fields, show alert if the same information is entered again
  function compare() {
 
  var text1 = document.getElementById("Address1");
  var text2 = document.getElementById("Address2");
 
  if (text1.value == text2.value) {
    alert("IMPORTANT\n\nYou have already entered that information in the previous field, you do not need to enter it again");
    //remove the duplicate info
    document.getElementById('Address2').value = "";
  }
}
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 1 month 3 weeks ago by iceferret.
The administrator has disabled public write access.
The following user(s) said Thank You: info4344

Cannot have the same value as another field 1 month 3 weeks ago #43313

  • info4344
  • info4344's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Awesome, thank you very much!
The administrator has disabled public write access.

Cannot have the same value as another field 1 month 2 weeks ago #43323

  • info4344
  • info4344's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
I added one more control since my diabolical users managed to breach it by typing the emails differently like " This e-mail address is being protected from spambots. You need JavaScript enabled to view it " and " This e-mail address is being protected from spambots. You need JavaScript enabled to view it ":
  var field1 = document.getElementById("Email1");
  var field2 = document.getElementById("Email2");
  var text1 =  field1.value.toLowerCase();
  var text2 =  field2.value.toLowerCase();
 
  if (text1 == text2) {
The administrator has disabled public write access.

Cannot have the same value as another field 1 month 2 weeks ago #43324

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 216
  • Thank you received: 57
yes, I do similar but with different functions as they cover lots of fields, basically to lower case or upper case the first letter or for names to deal with surnames like D'Eath. It's so that the data in the database is consistent and when extracted for print lists it looks correct as well.
Usefull addition as you've used it.
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
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!