• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 806
  • Last Modified:

Javascript Disable URL Form

I would like to disable people from inserting links into my form. Are there any tutorials out there for this?
0
Nitestarz
Asked:
Nitestarz
  • 3
2 Solutions
 
mzalfresCommented:
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
 
v2MediaCommented:
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
 
NitestarzAuthor Commented:
Yes, PHP is used to process the page.
0
 
v2MediaCommented:
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
 
v2MediaCommented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now