Developer forum

Forum » CMS - Standard features » How to validate in "Forms for editors"

How to validate in "Forms for editors"

Lise T. Pedersen
Reply

I can see in the forum, that a lot, other than me, have had troubles finding the templates for the Forms for Editors, but I had good help for this.

Now - another problem is how to validate the different form elements (e.g. email - only numbers and so on), Can I find some documentation on that somewhere, or can someone help me with some hints?

My solution is version 8.6 at the moment...

/Lise


Replies

 
Nicolai Høeg Pedersen
Reply

You can use the validation.js script we have talked about before:

http://developer.dynamicweb.com/forum/templates/forms-for-datalists-two-input-fields-with-password-how-to-check.aspx

Or use Jquery validate.

The module does not yet contain built in validation.

BR Nicolai

 
Lise T. Pedersen
Reply

Okay - was not sure I could use the "usual" script, but it helps me some of the way - the only thing is where to in input the "validate values" if fx "integer" or "email" is needed for a certain field? Maybe it's me who's blind, but I can't find fields for this??

BR
Lise

 
Nicolai Høeg Pedersen
Reply

Hi Lise

You have to add it to the template or you can add a hidden field to the form with a validation value.

BR Nicolai

 
Lise T. Pedersen
Reply

Hi again, Nicolai (and others)

I've just upgraded to DW8.8, and the html5-validation saved me, and seems to work perfekt.

I have only one problem so far - I use the "number" validation for phonenumbers, but the maxlength of 8 caracters need to be outputted in another way than the template does, the control "maxlenght" is not useful here. How do I change it in the cshtml template, to make it work - as far as I can see, it must be this way instead: <input type="number" name="telefon" max="8">

I have also tried the type "tel" but found out it was only working in Safari so far...

 

 

 
Nicolai Høeg Pedersen
Reply

That is a bug, just fixed and ready for 8.8.1

Untill then you can do like this (snip from the default template with yellow as add-on):

@foreach (LoopItem field in GetLoop("Fields"))
                {
                    int fieldId = field.GetInteger("Field.ID");
                    string fieldHtmlId = field.GetString("Field.HtmlId");
                    string fieldName = field.GetString("Field.Name");
                    string fieldControl = field.GetString("Field.Control");
                    string fieldDescription = field.GetString("Field.Description");
                    bool fieldIsButton = field.GetBoolean("Field.IsButton");
                    bool fieldIsOther = field.GetBoolean("Field.IsOther");
                    bool fieldRequired = field.GetBoolean("Field.Required");
                    string fieldType = field.GetString("Field.Type");
                    if(fieldType == ""){
                        fieldControl = fieldControl.Replace("maxlength", "max");
                    }

 
Lise T. Pedersen
Reply

Unfortunately, I get this error:

Line 85: The name 'fieldType' does not exist in the current context

Do you think I need a newer version of the default template - mine is from february?

/Lise

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Did you copy over the first line of Nicolai's highlighted code? That's where fieldType gets declared.

Imar

 
Lise T. Pedersen
Reply

My mistake - I did some tests and copy-pasted the code a couple of times - and the line was disappeared, suddenly! Thank you!

 

You must be logged in to post in the forum