Contact Form Field

I need to create a field in the contact form so that it requires a specific word before the form will send. I.E **London**. I need to replicate the field a number of times and have a different word to be entered. Is this possible with a bit of coding???

$w.onReady(() => {
    $w('#input').onCustomValidation((value, reject) => {
        if (!value.includes('London')) reject('The word London is missing!')
    })
})

Just to note, the code above simply checks if ‘London’ appears anywhere at all within the text, that would also include as part of a larger word such as ‘Londoners’

But it does will not validate the word ‘london’
To make it case insensitive, use:

if (!value.toLowerCase().includes('london')) reject('The word London is missing!')

(Or toLocaleLowerCase, I do not know the distinction)

Thank you very much Dean. This looks spot on…The only problem now it where do I add the code? I assumed it would be on the form field itself somewhere, but i have been through all the field settings…I cannot find anywhere to add it.

On the top toolbar, click on “Dev Mode” and turn it on

Then, you’ll have access to the page’s code

$w.onReady - Runs when the page is ready, and the elements are loaded
$w.Input.onCustomValidation - Runs when user exits a field, to check if the input is valid

Hi Dean

Thank you for your help.

I cannot get that code to work (It might be me adding it incorrectly…!!!)

If you look here www.oxfordshire-quiz-league.com/test

This is the basis of what I am trying to do with 10 pics per page.

It looks as though there is a problem with this…!!! It is underlined red in the code.

(‘#input’)

I have the code added to the London Form Field only at the moment…but it will still take any answer in the field.

May I ask what exactly you are trying to achieve?

If this is a quiz, then input validation is not what you’re looking for

The input validation is made to let the user know the value they entered does not match the requirements, and block them from submitting the form. It is done on the client’s machine (So technically it can still be bypassed) and immediately highlights the field according to the style defined (red border by default)

Since forms are not submitted if the fields are invalid - All your submitted quizzes will be correct by design.

For the answers to be unknown to the clients browsing your computer, you would need the validation and perhaps scoring to be handled by the server.


As for the error you’re experiencing, I should’ve clarified initially.

#input is the element tag, change it to the element tag defined for the input field you want to validate

Hi Dean, Thank You…Yes that is what I wanted.

I was just trying to find a different way of presenting a picture quiz on different levels.

When the form is submitted (Which will only happen when all answers are correct) they will receive an email or Wix Automation with the password to the next level.

I have tried different Quiz software packages, but they cost a fortune and this is just for fun when the season ends.