Submit Your Article Forum Rules

Results 1 to 5 of 5

Thread: Script to disallow URLs from form fields?

  1. #1
    Senior Member Tim's Avatar
    Join Date
    Jul 2004
    Posts
    422

    Script to disallow URLs from form fields?

    My clients are constantly plagued by form responses filled with spammers' links.

    I currently use .htaccess to block known spammers, a temporary solution but one that also bans whoever inherits the IPs, and image CAPTCHAs to block spambots but I realise these are not accessible. I also display the visitor's IP as a deterrent.

    As spammers are mostly driven by including URLs in their polluting contributions, it would seem logical that a script that bars 'http' and 'www' from being submitted in any form fields would reduce this type of spam enormously. In most cases URLs are not required anyway.

    Please can anyone link to/write such a validation script?

    Many thanks,

    Tim
    Pleasure in the job puts perfection in the work. Aristotle (384-322 BC)

  2. #2
    Senior Member sands's Avatar
    Join Date
    Sep 2005
    Posts
    392
    If it is PHP you could have something like this:
    Code:
    if ((strstr(strtolower($fieldName), 'http://')) || (strstr(strtolower($fieldName), 'www'))) {
      print "No links are accepted in the ______ field!";
      return; }

  3. #3
    Senior Member Tim's Avatar
    Join Date
    Jul 2004
    Posts
    422
    Thanks Sands,

    Unfortunately, all existing forms are handled by FormMail Perl with JavaScript validation so I don't think I can make your solution work, unless you know otherwise? I use PHP for the "REMOTE_ADDR" display but that doesn't write to the form.

    I have been considering mass conversion to PHP but that would/will mean a lot of work for dozens of sites. Eek!

    Thanks again for the nice script that I will use in future.
    Pleasure in the job puts perfection in the work. Aristotle (384-322 BC)

  4. #4
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    760
    Then do it in JavaScript.

    On the form submit button, direct it to a JavaScript function instead of directly submitting the form. This function can then search the post entry for the offending text. if it isn't there, call the forms submit function.

    You can use the same function for other form validation too, such as ensuring the poster puts in an e-mail address or other required field.

    From your post, it sounds like you are already calling a JavaScript function before form submission so this should be a simple addition to it.
    Dynamic Software Development
    www.activeminds.ca

  5. #5
    Senior Member Tim's Avatar
    Join Date
    Jul 2004
    Posts
    422
    Thanks Dave but I'm sure most form-spammers have JavaScript disabled.
    Pleasure in the job puts perfection in the work. Aristotle (384-322 BC)

Similar Threads

  1. Count certain form fields containing any value using asp? or javascript?
    By Katt in forum Web Programming Discussion Forum
    Replies: 8
    Last Post: 03-15-2010, 09:50 AM
  2. Good Form and Form to Email Script
    By Burty in forum Graphics & Design Discussion Forum
    Replies: 9
    Last Post: 03-13-2009, 07:40 PM
  3. PHP help needed with existing script - adding more fields
    By webgurl in forum Web Programming Discussion Forum
    Replies: 1
    Last Post: 03-22-2006, 09:10 PM
  4. multipage HTML form with hidden fields
    By webgurl in forum Web Programming Discussion Forum
    Replies: 1
    Last Post: 03-15-2006, 07:54 AM
  5. Mandatory fields in a form (formmail)
    By aventvoy in forum Web Programming Discussion Forum
    Replies: 4
    Last Post: 11-17-2005, 12:45 AM

Posting Permissions

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