ChronoEngine Forums
Welcome, Guest
Please Login or Register.    Lost Password?
Using JavaScript validation (2 viewing) (2) Guests
Go to bottom Post Reply Favoured: 3
TOPIC: Using JavaScript validation
#1329
GreyHead (Admin)
Support
Admin
Posts: 2902
graph
User Offline Click here to see the profile of this user
Gender: Male bobjanes Location: Brittany
Using JavaScript validation 1 Year ago Karma: 62  
Hi,

Caution: I'm no JavaScript expert so there may be errors in this post. If you find any let me know and I'll fix them.

ChronoForms makes it easy to include validation JavaScript with your form but there are some problems in using JavaScript from other sources or existing forms.

Mostly there are two problems:
  • ChronoForms changes the form name and the JavaScript doesn't recognise it.
  • How to call the JavaScript validation - what code to put where.
I'll describe here a basic method that should fix most of these problems. There are other methods that may work as well or better for you.

The form name

ChronoForms changes the form name you use in the Form Manager. If you enter 'my_form' the ChronoForms form will be called 'ChronoContact_my_form'. This is probably the biggest cause of JavaScript validation problems.

Validation scripts usually start with a line like 'function checkForm()' or 'function checkForm(form)' and these two handle the form name in different ways.

Style 1: 'function checkForm()'

The form is usually addressed with the code 'document.{form_name}' e.g. 'document.my_form'

To use this style with ChronoForms you would need to find and replace each 'document.my_form' with 'document.ChronoContact_my_form'. This is tedious and has to be repeated if you want to use the same validation with another form.

Instead I suggest that you change your JavaScript to the second style of function.

Style 2: 'function checkForm(form)'

This style of function uses the JavaScript variable 'form' to identify the form and the actual form name is passed to the function when it is called.

If your JavaScript has the other style, then change the function header to the 'checkForm(form)' style and replace every occurrence of 'document.{form_name}' with 'form' so that 'document.my_form.some_code' becomes 'form.some_code' etc.

Calling the JavaScript

Once you have edited the JavaScript to use the 'checkForm(form)' you can call it simply by adding this code into the ChronoForms 'Form tag attachment' field:
Code:

onSubmit="return checkForm(this)"
Using 'this' here will mean that the correct form name is automatically passed to the JavaScript. The 'return' means that the form will only be submitted if the JavaScript validation returns 'true' - this is how validation scripts are usually written so is unlikely to be a problem. Here is a very simple example of a validation script written like this, it simply validates that the form field 'name' is not empty :
Code:

function checkForm(form) { if(form.name.value == "") { alert("Please enter your name!"); return false; } return true; }
Bob<br><br>Post edited by: GreyHead, at: 2007/07/20 11:34
 
Report to moderator   Logged Logged  
 
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
  The administrator has disabled public write access.
#3104
goranbaxy (User)
Fresh Boarder
Posts: 13
graphgraph
User Offline Click here to see the profile of this user
Re:Using JavaScript validation 8 Months, 3 Weeks ago Karma: 0  
Here is my JS code:
Some text is on Croatian
but if I catch some time I'll translate it!
Code:

function validate_email(field,alerttxt) { with (field) { apos=value.indexOf(&quot;@&quot;) dotpos=value.lastIndexOf(&quot;.&quot;) if (apos&lt;1||dotpos-apos&lt;2) {alert(alerttxt);return false} } } function checkForm(form) { /* IME */ if(form.name.value == &quot;&quot;) { alert(&quot;Niste unjeli ime!&quot;); return false; } /* PREZIME */ if(form.subname.value == &quot;&quot;) { alert(&quot;Niste unjeli prezime!&quot;); return false; } /* MAIL */ with (form) { if (validate_email(email,&quot;Niste unjeli ispravnu mail adresu!&quot;)==false) {email.focus();return false} } /* TELEFON */ if(form.tel.value == &quot;&quot;) { alert(&quot;Niste unjeli broj telefona!&quot;); return false; } /* ADRESA */ if(form.adresa.value == &quot;&quot;) { alert(&quot;Niste unjeli adresu!&quot;); return false; } /* KU&amp;#262;NI BROJ */ if(form.kbroj.value == &quot;&quot;) { alert(&quot;Niste unjeli ku&amp;#263;ni broj!&quot;); return false; } /* POŠTANSKI BROJ */ if(form.posta.value == &quot;&quot;) { alert(&quot;Niste unjeli poštanski broj!&quot;); return false; } /* GRAD */ if(form.grad.value == &quot;&quot;) { alert(&quot;Niste unjeli grad!&quot;); return false; } /* ŽUPANIJA */ if(form.zupanija.value == &quot;21&quot;) { alert(&quot;Niste izabrali županiju!&quot;); return false; } /* Ovo se izvršava nakon svih provjera! */ return true; }
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#3107
admin (Admin)
Admin
Posts: 1631
graphgraph
User Online Now Click here to see the profile of this user
Re:Using JavaScript validation 8 Months, 3 Weeks ago Karma: 23  
hi goranbaxy,

do you put the checkform(this) in the right field in Chronoforms? is your form online somewhere ?

Max<br><br>Post edited by: admin, at: 2007/10/26 15:02
 
Report to moderator   Logged Logged  
 
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
  The administrator has disabled public write access.
#3110
goranbaxy (User)
Fresh Boarder
Posts: 13
graphgraph
User Offline Click here to see the profile of this user
Re:Using JavaScript validation 8 Months, 3 Weeks ago Karma: 0  
In &quot;Form tag attachment:&quot; I have: &quot;enctype='multipart/form-data' onSubmit=&quot;return checkForm(this)&quot;&quot;
everthing is working but it's still not online as it needs some design.
I have put the the html + js code in &quot; Share your forms with others&quot;
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#3114
admin (Admin)
Admin
Posts: 1631
graphgraph
User Online Now Click here to see the profile of this user
Re:Using JavaScript validation 8 Months, 3 Weeks ago Karma: 23  
Conversation moved here :<br><br>Post edited by: GreyHead, at: 2007/11/06 15:58
 
Report to moderator   Logged Logged  
 
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
  The administrator has disabled public write access.
#8479
sailsmart (User)
Junior Boarder
Posts: 21
graphgraph
User Offline Click here to see the profile of this user
html tidy 2 Months ago Karma: 0  
On the validating a form thread, can I just press the validate at the bottom of the live form which redirects to a website which shows all line errors, then the choice to use html tidy to fix. This usually helps when using an alternate editor like Dreamweaver. I think I still then have to take out some of the head tags and form tags. Does anyone else do this?
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop


equalheight If you have any questions you can post to our forums and we will be glad to help ASAP

Members Login






Lost Password?
No account yet? Register

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for
goods and services provided by ChronoEngine.com

ChronoForms License

equalheightTo be able to continue working at this component we decided to get a small profit out of it but at the same time don't force everybody to pay in order to use this great component.

 

 From version 1.5 and up a link at the bottom of everyform created will be placed, saying "joomla professional work", the link will be to us here htttp://www.chronoengine.com, its illegal to remove this link from the source code unless you have a license,

so the license is very simply for the same ChronoForms component without a link, thats all!

This License is for 5 different websites ONLY. 

 

 However, in order to allow everybody to still use the component and even get out of this, the link is inside a div with class : chronoform , use this to hide the link by using different colors or whatever if you really can't pay, but of course the link is still exists at your page source.

 

The license is ONLY 25$ can be bought here :

 

Thank you!

 

ChronoEngine.com Team 

Joomla Templates and Joomla Tutorials