+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
Web Development Thread, Web-based contact form being abused in Coding and Web Development; I have two pices of javascript that i am trying to get to work together nicely. the first is validation ...
  1. #16

    Join Date
    May 2006
    Location
    West Bromwich
    Posts
    2,192
    Thank Post
    300
    Thanked 215 Times in 185 Posts
    Rep Power
    57

    Re: Web-based contact form being abused

    I have two pices of javascript that i am trying to get to work together nicely.
    the first is validation of the fields of the form:

    <script language="javascript">

    function validate() {
    var mNv=enquiry.Name.value;
    var mCv=enquiry.Comments.value;
    var email=enquiry.Email.value;

    if (mNv=='') {
    alert('Your name is a required field. Please try again.');
    event.returnValue=false;
    }
    if (mCv=='') {
    alert(' Your message is empty. Please enter a message to send.');
    event.returnValue=false; }

    validate_message();

    //email validation

    AtPos = email.indexOf("@")
    StopPos = email.lastIndexOf(".")
    Message = ""
    if (email == "") {
    alert('Email address is blank' + "\n");
    event.returnValue=false;

    }
    if (AtPos == -1 || StopPos == -1) {
    alert('Not a valid Email address');
    event.returnValue=false;

    }
    if (StopPos < AtPos) {
    alert('Not a valid Email adress');
    event.returnValue=false;

    }
    if (StopPos - AtPos == 1) {
    alert('Not a valid Email address');

    event.returnValue=false;
    }
    }

    </script>
    ----------------------------------------------------------

    The second is validation of the Comments field (checks for bad language):

    <script language="javascript">

    // Enter the words to be filtered in the line below:

    var swear_words_arr=new Array("bloody","war","terror");

    var swear_alert_arr=new Array;
    var swear_alert_count=0;
    function reset_alert_count()
    {
    swear_alert_count=0;
    }
    function validate_message()
    {
    reset_alert_count();
    var compare_text=document.enquiry.Comments.value;
    for(var i=0; i<swear_words_arr.length; i++)
    {
    for(var j=0; j<(compare_text.length); j++)
    {
    if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
    {
    swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
    swear_alert_count++;
    }
    }
    }
    var alert_text="";
    for(var k=1; k<=swear_alert_count; k++)
    {
    alert_text+="\n" + "(" + k + ") " + swear_alert_arr[k-1];
    }
    if(swear_alert_count>0)
    {
    alert("The form cannot be submitted.\n You have used innappropriate language.");
    document.enquiry.Comments.select();
    event.returnValue=false;
    }
    else
    {
    document.enquiry.submit();
    }
    }
    function select_area()
    {
    document.enquiry.Comments.select();

    }
    window.onload=reset_alert_count;

    </script>
    ------------------------------------------------------

    Before the second script was added the form was validated OK, but after the second was added the Comments box was validated for bad language but if it was left empty was accepted.

    I think it has something to do with the swear validation saying no swearing found so accept the message and overiding the other validation rule. How can i resolve this problem.

  2. #17

    Join Date
    May 2006
    Location
    West Bromwich
    Posts
    2,192
    Thank Post
    300
    Thanked 215 Times in 185 Posts
    Rep Power
    57

    Re: Web-based contact form being abused

    I have resolved the javascript issue. Just removed the else statement as it was obviously just submitting when no errors were found instead of just halting if errors were found.

    I would prefer a server side version though if anyone is willing (i will have a go as well of course, although it may get finished when i'm 75 and retired

  3. #18
    gibbo_ap's Avatar
    Join Date
    Nov 2007
    Location
    Staffs, UK
    Posts
    937
    Thank Post
    233
    Thanked 81 Times in 64 Posts
    Rep Power
    37

    Re: Web-based contact form being abused

    easy, have a bit of script which searches through for swear words if it contains swear words redirect the mail to you (but with a certain subject header, which then you set a rule in outlook to put this in a relivent folder) then check if it is valid or not if it is 4wd to who ever

SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Contact Form Not Working
    By FN-GM in forum EduGeek Joomla 1.0 Package
    Replies: 9
    Last Post: 15th February 2008, 12:12 PM
  2. How would you like to contact technical support?
    By StuartC in forum Educational Software
    Replies: 17
    Last Post: 17th October 2007, 01:33 PM
  3. Play.com Contact details???
    By timbo343 in forum General Chat
    Replies: 3
    Last Post: 14th September 2007, 09:31 AM
  4. Contact with kids
    By RoyG in forum General Chat
    Replies: 15
    Last Post: 23rd January 2006, 11:17 AM
  5. those trying to contact me
    By russdev in forum Other Stuff
    Replies: 11
    Last Post: 15th September 2005, 06:59 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •