bookish Posted December 3, 2014 Report Share Posted December 3, 2014 Hello! I would like to ask help on disabling a form or a way for a signup not to proceed because an authentication field is erroneous (e.g. the birthday has the year between 2000 and 2014). Thank you. Quote Link to comment Share on other sites More sharing options...
Jan Posted December 3, 2014 Report Share Posted December 3, 2014 Hello bookish, You can add a Header&Footer element, select the Footer element, click the Source button and enter the following JavaScript code, that will check the field: <SCRIPT LANGUAGE="JavaScript"> function check_date() { var entered_value = document.getElementById("InsertRecorddate_value").value; var entered_date = new Date(entered_value); var entered_year = entered_date.getFullYear(); var today = new Date(); var current_year = today.getFullYear(); var allowed_years = 15; if(current_year - entered_year < allowed_years) { alert("Incorrect Birthday."); return false; } } document.getElementById("caspioform").onsubmit=check_date; </SCRIPT> Please, insert the name of your field instead of "date_value" in the following line: var entered_value = document.getElementById("InsertRecorddate_value").value; You can also enter you message instead of "Incorrect Birthday." and change the value of "allowed_years". I hope, it helps. bookish 1 Quote Link to comment Share on other sites More sharing options...
bookish Posted December 3, 2014 Author Report Share Posted December 3, 2014 Great! It worked! Thank you very much, Jan Quote Link to comment Share on other sites More sharing options...
Jan Posted December 3, 2014 Report Share Posted December 3, 2014 You are welcome! Quote Link to comment Share on other sites More sharing options...
Aurora Posted November 5, 2015 Report Share Posted November 5, 2015 Hi Jan, This script works, thanks you. However, if user had birthday this year, he is still unable to log in until next year. Any help will be appreciable. Quote Link to comment Share on other sites More sharing options...
Jan Posted November 5, 2015 Report Share Posted November 5, 2015 Hi Aurora, You are right, it was not completely good code. You can use the update code (please, enter the name of you field instead of FIELDNAME and the correct number instead of "15": <SCRIPT LANGUAGE="JavaScript"> function check_date() { var field_name = "FIELDNAME"; var allowed_years = 15; field_name = "InsertRecord" + field_name; var entered_value = document.getElementById(field_name).value; var entered_date = new Date(entered_value); var entered_year = entered_date.getFullYear(); var today = new Date(); var current_year = today.getFullYear(); var denied = false; if(current_year - entered_year <= allowed_years) { if (current_year - entered_year == allowed_years) { var entered_month = entered_date.getMonth(); var current_month = today.getMonth(); if (current_month <= entered_month) { if (current_month == entered_month) { var entered_day = entered_date.getDate(); var current_day = today.getDate(); if (current_day < entered_day) denied = true; } else denied = true; } } else denied = true; } if (denied) { alert("Incorrect Birthday."); return false; } } document.getElementById("caspioform").onsubmit=check_date; </SCRIPT> I hope, it helps. Quote Link to comment Share on other sites More sharing options...
Aurora Posted November 5, 2015 Report Share Posted November 5, 2015 This helped a lot. Thank you, Jan! Have a good day Quote Link to comment Share on other sites More sharing options...
bookish Posted December 19, 2018 Author Report Share Posted December 19, 2018 Hi Jan and Aurora, Is this script still working for you? It has stopped working in my program, I do not see the alert anymore. I would appreciate your feedback. Thanks! Quote Link to comment Share on other sites More sharing options...
TsiBiRu Posted December 19, 2018 Report Share Posted December 19, 2018 <script type="text/javascript"> document.addEventListener('BeforeFormSubmit', function (event) { function check_date() { var field_name = "FIELDNAME"; var allowed_years = 15; field_name = "InsertRecord" + field_name; var entered_value = document.getElementById(field_name).value; var entered_date = new Date(entered_value); var entered_year = entered_date.getFullYear(); var today = new Date(); var current_year = today.getFullYear(); var denied = false; if(current_year - entered_year <= allowed_years) { if (current_year - entered_year == allowed_years) { var entered_month = entered_date.getMonth(); var current_month = today.getMonth(); if (current_month <= entered_month) { if (current_month == entered_month) { var entered_day = entered_date.getDate(); var current_day = today.getDate(); if (current_day < entered_day) denied = true; } else denied = true; } } else denied = true; } if (denied) { alert("Incorrect Birthday."); return false; } } document.getElementById("caspioform").onsubmit=check_date; }); </script> Hi @bookish, I think the reason why this codes has stopped working for you is because of the release 13.0 of the platform on July 11, 2018, because of this release some of the JavaScript codes that we already have needs to be updated. For more details about this you can check this link https://howto.caspio.com/release-notes/caspio-bridge-13-0/13-0-impacted-areas/ You can also try to use the code above, and see if that works. I just added some line of code in it. And you can also try to disable the Ajax loading in your DataPage by clicking the the check box http://prntscr.com/lx292i , you can see this option in the 'DataPage Data Source' tab / part of your DataPage. Regards, TsiBiRu Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.