Jump to content

Disable A Form For Wrong Entry


Recommended Posts

Hi bookish,

 

Can you use drop-down lists instead of input fields?

You can use Lookup tables with variants of special diets and special room requests.

 

 

You can look for some words in the field with the following code:

<SCRIPT LANGUAGE="JavaScript">
function check_text()
{
var text_for_checking = document.getElementById("InsertRecordtext").value;
var wrong_answer = false;
if (text_for_checking.search("room")!=-1) {wrong_answer = true};
if (text_for_checking.search("floor")!=-1) {wrong_answer = true};
if (wrong_answer)
   {
      alert("Please specify your diet requirement.");
      return false;
   }
}
document.getElementById("caspioform").onsubmit=check_text;
</SCRIPT>

Please, enter the name of your field instead of text in the 

var text_for_checking = document.getElementById("InsertRecordtext").value;

 

You can add as many words as you wish, just copy the line

if (text_for_checking.search("room")!=-1) {wrong_answer = true};

and enter your word instead of "room".

 

To use a Java Script code, please add a Header&Footer element, select the Footer element, then click the Source button, and then enter a code. 
 
I hope it helps.
Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
  • 8 years later...

Hi! Would anyone help rewrite this script now that onsubmit will not work anymore (re disable ajax loading)?  Thanks in advance!

On 1/15/2015 at 4:07 PM, Jan said:

Hi bookish,

 

Can you use drop-down lists instead of input fields?

You can use Lookup tables with variants of special diets and special room requests.

 

 

You can look for some words in the field with the following code:

<SCRIPT LANGUAGE="JavaScript">
function check_text()
{
var text_for_checking = document.getElementById("InsertRecordtext").value;
var wrong_answer = false;
if (text_for_checking.search("room")!=-1) {wrong_answer = true};
if (text_for_checking.search("floor")!=-1) {wrong_answer = true};
if (wrong_answer)
   {
      alert("Please specify your diet requirement.");
      return false;
   }
}
document.getElementById("caspioform").onsubmit=check_text;
</SCRIPT>

Please, enter the name of your field instead of text in the 

var text_for_checking = document.getElementById("InsertRecordtext").value;

 

You can add as many words as you wish, just copy the line

if (text_for_checking.search("room")!=-1) {wrong_answer = true};

and enter your word instead of "room".

 

To use a Java Script code, please add a Header&Footer element, select the Footer element, then click the Source button, and then enter a code. 
 
I hope it helps.

 

Link to comment
Share on other sites

Hello @bookish,

You can use the following code instead:

<script>
document.addEventListener('BeforeFormSubmit', checkValuesHandler)

function checkValuesHandler(event){
    const textField = document.querySelector('#InsertRecordFIELDNAME').value; //replace FIELDNAME with your field name
    if(textField.includes('room') || textField.includes('floor') || textField.includes('bedroom')){
         event.preventDefault();
         alert('Please specify your diet requirement.');
    } 
}
</script>

You can add more conditions if needed. Just copy this part and replace the keyword.

|| textField.includes('KEYWORD')

 

You may use an additional tool for displaying pop-up messages instead of the basic browser alert.

For that, you can use the following code:

<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
document.addEventListener('BeforeFormSubmit', checkValuesHandler)

function checkValuesHandler(event){
    const textField = document.querySelector('#InsertRecordFIELDNAME').value; //replace FIELDNAME with your field name
    if(textField.includes('room') || textField.includes('floor') || textField.includes('bedroom')){
         event.preventDefault();
         Swal.fire( '', 'Please specify your diet requirement.', 'warning' );
    } 
}
</script>

This is an example:

hMEKSvl.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...