Hello,
I would like to have users input either their telephone number or email address.
Is It possible to make a *one or the other* situation?
Thank you.🙂
Hi driv,
You mean in fields validation ? if yes then yes you can, but you will need a custom validation function, you will actually need 2 functions, one for each field, this FAQ should help you for the v4:
https://www.chronoengine.com/faqs/54-cfv4/cfv4-validation/2656-how-can-i-add-a-custom-client-side-validation.html
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
In this case you will not need a regex, instead an a comparison:
function customCheck(el){
if (!el.value && !document.id("other_field_id").value) {
el.errors.push("you need to enter either your email or phone");
return false;
} else {
return true;
}
}
You will need 2 of this with 2 different names, each one setup for one of the 2 fields to check both of them in both cases.
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Thank you again - I do appreciate your responses.
However, I am unable to make this work.
I have added the function (above) to a Load JS action in the On Load event of the form.
I used telcheck and emailcheck as the IDs of the fields.
I added validate['required','%customCheck'] to the class boxes of each field.
However, it seems to me that the function is looking for other_field_id - so do I need to create two functions?
Actually, I tried this - each with the telcheck or emailcheck as IDs - but I couldn't get it to work.
Do you think you could explain where I am going wrong?
Thank you.
Please post the 2 functions you have!
Moreover, they should have 2 different names because they do 2 different checks depending on the field which does the trigger!
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Ok, the "other id" used inside the function should NOT match the function name, e.g, inside the "telCheck" you should use "emailCheck" to test the other field!
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
You should not have the "required" in both fields, so please change it to:
validate['%emailCheck']
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
ok - I have done that, validate['%emailCheck'] ...but now the form doesn't validate either field.
This is with the field validation checkbox not checked.
When I do check that box - it wants to validate both fields.
Ok, please try to change the validation function in one of the functions to:
if (!el.value){
Does this make the field required ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
You still don't get any errors ? if yes then please add:
alert(el.value);
after this line:
function telCheck(el){
Now try to submit the form but make sure that there is at least one required field AFTER the tel/email fields, do you get an alert box ? what does it contain ?
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Ok, now please remove that new line and try to change:
!el.value
to
el.value == ''
Does it display the error when the field is empty ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Does the field have an empty space in it ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
I'm sorry did you mean the form input field? Or el.value == ' '
Maybe the validation doesn't work, please try this:
function telCheck(el){
return false;
}
Does it show anything when you submit the form ? I suggest that you add "Title" to your field, this will be used as the error message.
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Yes, but I wanted to make sure that the custom functions are called and processed as expected, it looks like they are called, but the return false we used should always make the validation fail, however, this didn't happen here.
This is v4, correct ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Yes, that's correct.
Version 4.0.4
Would you like me to send log-in details, by PM?
Hi driv,
Yes, please do!
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
v5 has different syntax, you should replace:
document.id ----> jQuery
.value ----> .val()
You will also need to add the custom functions names to both fields validation sections, and you should not have the required box enabled!
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Please change validate['%emailCheck'] to validate['custom:emailCheck']
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi, I have the same problem with version 4. However, the solution ends abruptly, so i'm not sure what to do next.
I get the same problem with validation not occuring, or blank pop-up box appearing. Please help?
Hi anandmahey,
There is no information in your post to start to work out what is happening. What code have you used and where?
Bob
Hi anandmahey,
Please post a link to the form so I can take a quick look.
Bob
Hi Bob,
I made some edits, as the field IDs did not match and customCheck was supposed to be customerCheck.
How, validation still does not occur. Moreover, blank data is being submitted.
@driv, what's your current code used ?
@anandmahey, what happens when you simply set one of the fields as required ? does the validation work ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi again - I hope you won't mind, but I've sent you a pm.
Thanks.🙂
@anandmahey, I'm now confused, not sure you have v4 or v5, because your code is for v4, and your default validation doesn't work, so please start a new topic with your details.
@driv, I will check that!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi Max,
apologies for the confusion. I have both V4 and V5 installed. You see, i have been following this thread for a solution. I began with V4, and tried for 2 days unsuccessfully to get the validation working. Then i gave up with V4 and tried V5, and got the same results as @driv. My hope was that since the thread became quiet, the solution that was presented for V5 worked, but it did not.
After that i reverted to V4 to give it another shot. Hope that clears the confusion. I still have V5 installed though.
Thank you.
Hi driv,
You have 3 problems:
#1- the custom function should gets the calling element, and so you should check its value + the value of the "other" element, this is wrong in your case, you call the "emailCheck" by the "telephone" field which then checks the calling element value + the "telephone" field value, so please correct this by calling the "emailCheck" using the "email" field..etc
#2- The logic operator should be || but not &&, since you need "either or"
#3- in v5 the selector should be jQuery("#email"), please note that "#" character, in v4 that was not needed.
@anandmahey, there are many differences between the 2 solutions, I hope my response above gives you some hints, but the v4 solution should be very well covered on other forums posts and on the FAQs
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
The "emailCheck" function should have:
jQuery("#telephone")
and vice versa.
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi,
ok I've made the changes - the form still won't submit. The error remains the same.
(The value entered is not valid)
Sorry to bump - just wondering if there were any further thoughts on this?
Please contact me using the "contact us" page and I will create a demo form for you with 2 fields and the code required, that will be for v5
Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?