Solved

Javascript Disable URL Form

Posted on 2007-04-10
7
800 Views
Last Modified: 2008-02-01
I would like to disable people from inserting links into my form. Are there any tutorials out there for this?
0
Comment
Question by:Nitestarz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
mzalfres earned 25 total points
ID: 18881813
Hi,

I'd search for regular expression defining any/specific URL and then create script running with 'onSubmit' event, which will check the form against this.

Something like in this example:

http://snippets.dzone.com/posts/show/452

If 'is_URL' function returns true, issue alert/error/whatever else and stop submitting form.

Regards,

Marek ZJ.
0
 
LVL 19

Expert Comment

by:v2Media
ID: 18882023
Javascript will not do it for you; it's too easily disabled. If you want to forbid links in your form data, then you have to do it server-side. Does your server support asp or php or any other server-scripting language?
0
 

Author Comment

by:Nitestarz
ID: 18882085
Yes, PHP is used to process the page.
0
 
LVL 19

Assisted Solution

by:v2Media
v2Media earned 25 total points
ID: 18882570
ok, lets say you want to show an error message to alert the user that links are not permitted. In the form processing portion of your script, include something along these lines:-

Assume $_POST['Submit'] is your form's submit button.

<?php
if(isset($_POST['Submit'])) {

      // reset onpage errors
      $onpageErrors = ''
      
      // concatenate POST vars to $strHaystack
      $strHaystack = '';
      foreach ($_POST as $index => $value){
      
            $strHaystack .= $value;
            
            }
      
      //detect link spammer
      $no_links = false;      
      $needles = '';
      
      //link needles
      $needles[] = '<a href';
      $needles[] = '=http:';
      $needles[] = '="http:';
      $needles[] = '=mailto:';
      
      foreach ($needles as $k => $v){
      
                  if( stristr($strHaystack,$v ) ){
                  $onpageErrors .= "Do not include links in this contact form. Use the format &quot;www.domain.com"; only.<br />";
                  break;
                  
                  }
            }
            
      if($onpageErrors == '') {
            //continue with form processing as usual
      
      }

}//end if form is submitted
?>

0
 
LVL 19

Expert Comment

by:v2Media
ID: 18882610
This is a snippet from a larger anti-spam script I use regularly. the line " $no_links = false;" can be deleted. Echo $onpageErrors someplace near your form if it doesn't = ''

e.g.

<?php
if($onpageErrors != '') {
?>
<div><?php echo $onpageErrors; ?></div>
<?php } ?>
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint and CAML query help 4 20
JQuery - Default innerhtml text with keyup function (copy as you type) 3 31
REST call Failing 1 34
Conformation code 4 31
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question