Solved

Javascript Disable URL Form

Posted on 2007-04-10
7
796 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Blog Template 2 37
jQuery detect if it is a mobile device 3 107
Facebook React and SyntheticEvents 6 49
how can i select 4 7
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now