Forums

validate-alphanum not working

jvince 02 Jun, 2009
Hi,
It seems that the validation option validate-alphanum does not work, as anything can still be input, not just letters and numbers.

Any fix appreciated.

- Vince
GreyHead 02 Jun, 2009
Hi Vince,

I think it's using an odd RegExp !/\W/ - that appears to be checking that the entry is not not a word character. (Double negative intended.) I think that has to be an error . . ., I'm not even sure that the ! works in a RegExp.

Bob
jvince 02 Jun, 2009
Hi Bob,
So how do we fix it, or need to wait for Max?
Thanks,
GreyHead 02 Jun, 2009
Hi Vince,

Try opening com_chronocontact/libraries/includes/JSvalidation2.php and look for this clode block around line 35
			if(field.hasClass('validate-alphanum')){
				var fMessage_val_validate_alphanum = 'Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed.';
				eval("if(field.getProperty('title')){fMessage_val_validate_alphanum = field.getProperty('title');}");
				eval("cfvalidate_"+field.getProperty('name')+".add( Validate.Format, { pattern: !/\W/, failureMessage: fMessage_val_validate_alphanum } );");
			}
the replace pattern: !/\W/, with pattern: /\w/,
Experimental - not tested - but it might work :-)

Bob
jvince 02 Jun, 2009
Hi Bob,
You got me all excited ... after that code change I tested with trying to input * > / and got the required message:

Please use only letters (a-z) or numbers (0-9) only in this field. No spaces or other characters are allowed



Unfortunately, that now happens whatever we input, including letters and/or numbers :-(
Max_admin 05 Jun, 2009
Hi Vince,

please get RC5.1 and try this, if it didn't work again then we now have an alternative route to add our custom validation which should work fine!

Regards
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 05 Jun, 2009
Hi Max,
Installed RC5.1 but still no different for alpha-num validation.
The JSvalidation2.php file no longer seems to have the pattern !/\W/

What is the alternative route to add our custom validation you mentioned to get this sorted?
We do need this to work because many company names have a combination of letters and numbers somestimes.

Many thanks,

- Vince
Max_admin 05 Jun, 2009
Hi Vince,

in RC5.1, add this code in the JS box:


window.addEvent('domready', function() {
var field_name = new LiveValidation('field_id');
field_name.add( Validate.Format, { pattern: /[A-Za-z ]/i } );
});


let me know!

Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 05 Jun, 2009
Hi,
May be worthwhile making sure I'm adding this code in the right place:

Form code -->> Form Javascript

Added your suggestion, but still allowing special characters: * & % / etc

Thanks,

- Vince
Max_admin 05 Jun, 2009
Hi Vince,

I checked your form, is this for the School field ?

if so then you need to replace field_name by "school" and need to add an id to your field, say "school" too and replace field_id by that "school"

so the final code should be:

    window.addEvent('domready', function() {
    var school = new LiveValidation('school');
    school.add( Validate.Format, { pattern: /[A-Za-z ]/i } );
    });


preferably, don't select this field as validated for alphanum in the validation tab, we add the validation manually here!

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 05 Jun, 2009
Hi,
Yes it is for the school field
I added 'school' in your js code now, and it attempts to validate now but not quite as it gives 'Not Valid' error while typing a special character but if you pass onto next field it turns green (valid).

It also does this with numbers. Does the js code need 0-9 added?

Here is the HTMl form code:
<h1 class="BlueDk">Contact Us</h1>

<p><strong>To take the next step or to find out more information, contact us now.</strong></p>

<table>
<tr><td>Name: </td><td><input name="name" value="" type="text"></td></tr>
<tr><td>Job Title: </td><td><input name="jobtitle" value="" type="text"></td></tr>
<tr><td>School: </td><td><input name="school" value="" type="text"></td></tr>
<tr><td>Email: </td><td><input name="email" value="" type="text"></td></tr>
<tr><td>Telephone: </td><td><input name="telephone" value="" type="text"></td></tr>
<tr><td>Comments: </td><td>
  
  <textarea name="comments">
</textarea>
  <input name="subject" value="CO2 Quote Request" type="hidden">
</td></tr>
<tr><td></td><td><input name="submit" value="Submit" type="submit"></td></tr>
</table><endendend>
Max_admin 06 Jun, 2009
Hi Vince,

you didn't add the id for the school field (id="school")

you will need to add 0-9 if you need the field to accept numbers!

your form link is no longer working and so I cant check it anymore!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 07 Jun, 2009
Hi Max,
The form link had to change as per your instructions, so same link as before but remove the two '-'

Not sure what you mean by id for school field.
I have <input name="school"
GreyHead 07 Jun, 2009
Hi jvince,

id and name are different
<input name="school" id="school" . . .

Bob
jvince 07 Jun, 2009
Hi Bob,
Thanks for your help and please excuse my ignorance.
Would we need to add an id to all form fields?

- Vince
GreyHead 08 Jun, 2009
Hi Jvince,

id's aren't required but they are highly desirable and my recommendation would be that you add them as a matter of course.

Usually the id can be the same as the name - but the id has to be unique so ths won't work for multiple submit buttons, radio button or checkbox groups. Here I add a numeric suffix radio0_1, radio0_2, . . .

The id is most often used by JavaScript - and if you aren't using any Javascript you can probably safely ignore them. The Mootools library has a short-cut to address a field which is $('field_id') and once you have that you can read or change pretty much any field attribute. (You can do the same with the name but it's nto so strightforward - and, if the name isn't unique, can cause problems.)

Note that you cna also use JavaScript plus ids on for example <div>s or <span>s to change their visibility or formatting, it's not just limited to form inputs.

Bob
jvince 08 Jun, 2009
Hi Bob,
really appreciate your explanation, thanks.

However, even after adding the id statement
<input name="school" id="school" value="" type="text"></

... the validation still lets through special characters 😲
I am at the end of my patience with this now.😟
Thanks,

- Vince
Max_admin 08 Jun, 2009
Hi Vince,

Ok, please resend me the form link and i will check it and try to find whats wrong!

Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 12 Jun, 2009
Hi Max,
I PM'ed you the link, have you had a chance to have a look?
many thanks,

- Vince
Max_admin 14 Jun, 2009
Hi Vince,

sorry but I was off for few days, just tested it and it works flawlessly!

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 15 Jun, 2009
Hi Max,
You tested the 'School' field?
It should only allow alpha-numeric, but instead allows special characters, ie. * & / %

Thanks
Max_admin 15 Jun, 2009
Hi Vince,

just tested again with FF 3 and IE7 and it will not allow @ or # or $ !!

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 15 Jun, 2009
I don't understand why it's different for you and me.
I have tested in both browsers on 2 different PC's on different phisical locations and networks.
Maybe you are testing onsubmit and I am testing before submit?

Here is a screenshot before submition.
[attachment=0]validationr.jpg[/attachment]

note the only error message missing is on Schools field. :-(

Thanks
Max_admin 16 Jun, 2009
Hi Vince,

what do you mean by "onsubmit" and before submit here ?

please try to test with @ or # ?

when you hit submit with % in the field, does it let you submit ?

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 16 Jun, 2009
I just meant before or after pressing the submit button.
I expected the validation on the schools field to work same way as the others - but it doesn't
The invalid error messages disappear once you move to another field, but this doesn't happen on the other fields so was confusing to me - and maybe other users?

If you do press the sub,it button with invalid entry within the schools field, the form does actually work as expected, in that the error message apears and the form does not get submitted.

Sorry for any confusion on this.

The other issue is I don't know how to change the code to make this field as originally intended: allow alpha-numeric.
Currently, no numbers are allowed.

Many thanks,
Max_admin 21 Jun, 2009
Hi Vince,

Just tested this and it works very fine here:


        window.addEvent('domready', function() {
        var school = new LiveValidation('school');
        school.add( Validate.Format, { pattern: /^[0-9a-zA-Z ]+$/i } );
        });

Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jvince 22 Jun, 2009
Perfect Max.
Thank you very much

- Vince
This topic is locked and no more replies can be posted.