jezella
asked on
Form Protection
I am trying to prevent a form from having website links input into various fields as I am being bombarded with these.
The following is an example of received emails and below is the code I use to check my form.
It is unfortunate that my example email could also providing these links from ee now so I have added an extra t to the http to prevent this
- - - - Contact Details - - - -
Enquiry Date: Good site! <a href=htttp://play-online-k eno.blogsp ot.com/>ke no</a> [url=htttp://play-online-k eno.blogsp ot.com/]ke no[/url]
First Name: keno
Last Name: keno
Address: usaa
Phone: 12345
E-mail: kenoas@gmail.com
- - - - Requirement and Date - - -
Date: 2018-08-28
Transport For: Other
Enquiring About: Good site! <a href=htttp://play-online-k eno.blogsp ot.com/>ke no</a> [url=htttp://play-online-k eno.blogsp ot.com/]ke no[/url]
- - - - Journey Details - - - -
Collection Place: Good site! <a href=htttp://play-online-k eno.blogsp ot.com/>ke no</a> [url=htttp://play-online-k eno.blogsp ot.com/]ke no[/url]
Ceremony Area: Good site! <a href=htttp://play-online-k eno.blogsp ot.com/>ke no</a> [url=htttp://play-online-k eno.blogsp ot.com/]ke no[/url]
Reception: Good site! <a href=htttp://play-online-k eno.blogsp ot.com/>ke no</a> [url=htttp://play-online-k eno.blogsp ot.com/]ke no[/url]
Hotel Location: Good site! <a href=htttp://play-online-k eno.blogsp ot.com/>ke no</a> [url=htttp://play-online-k eno.blogsp ot.com/]ke no[/url]
- - - - Vehicles Considered - - -
Dark Blue Jaguar - Fay: Interested
Dark Blue Mercedes - Blue: Interested
White Mercedes - Lady: Interested
Silver Spirit - Duchess: Interested
Silver Spirit - Patience: Interested
Silver Spirit - Mary: Interested
Silver Shadow - Tabatha: Interested
Bentley Arnage - Joy: Interested
Bentley R-Type - Amy: Interested
Bentley Mk 6 - Ruth: Interested
Bentley S1 - Emily: Interested
Continental - Goddess: Interested
Lagonda - Grace: Interested
- - - - Other Information - - -
Good site! <a href=htttp://play-online-k eno.blogsp ot.com/>ke no</a> [url=htttp://play-online-k eno.blogsp ot.com/]ke no[/url]
- - - - Enquiry Source Wedding
-------------------------- ---------- ---
My code is as follows
<script>
<!--
function validate(form) {
if (form.firstName.value.leng th == 0)
{
alert("Please enter your first name.")
form.firstName.focus()
return false
}
if (form.lastName.value.lengt h == 0)
{
alert("Please enter your last name.")
form.lastName.focus()
return false
}
if (form.email.value.length == 0)
{
alert("Please enter your e-mail address.")
form.email.focus()
return false
}
if (form.email.value.indexOf( "@") == -1)
{
alert("Please enter a valid e-mail address.");
form.email.focus();
return false;
}
if (form.selectDay.value == 0)
{
alert("Please Enter a Day.")
form.selectDay.focus()
return false
}
if (form.selectMonth.value == 0)
{
alert("Please Enter a Month.")
form.selectMonth.focus()
return false
}
if (form.selectYear.value == 0)
{
alert("Please Enter a Year.")
form.selectYear.focus()
return false
}
if (form.transType.value == "Please Select Usage")
{
alert("Please Select Transport For.")
form.transType.focus()
return false
}
if (form.requiredFor.value == "Please Select")
{
alert("Please Choose Required For Section.")
form.requiredFor.focus()
return false
}
if (form.collectionTown.value .length == 0)
{
alert("Please the Initial Collection Point.")
form.collectionTown.focus( )
return false
}
}
//-->
</script>
PLEASE help here and understand that I do not know anything about java
Many thanks
Ashley
The following is an example of received emails and below is the code I use to check my form.
It is unfortunate that my example email could also providing these links from ee now so I have added an extra t to the http to prevent this
- - - - Contact Details - - - -
Enquiry Date: Good site! <a href=htttp://play-online-k
First Name: keno
Last Name: keno
Address: usaa
Phone: 12345
E-mail: kenoas@gmail.com
- - - - Requirement and Date - - -
Date: 2018-08-28
Transport For: Other
Enquiring About: Good site! <a href=htttp://play-online-k
- - - - Journey Details - - - -
Collection Place: Good site! <a href=htttp://play-online-k
Ceremony Area: Good site! <a href=htttp://play-online-k
Reception: Good site! <a href=htttp://play-online-k
Hotel Location: Good site! <a href=htttp://play-online-k
- - - - Vehicles Considered - - -
Dark Blue Jaguar - Fay: Interested
Dark Blue Mercedes - Blue: Interested
White Mercedes - Lady: Interested
Silver Spirit - Duchess: Interested
Silver Spirit - Patience: Interested
Silver Spirit - Mary: Interested
Silver Shadow - Tabatha: Interested
Bentley Arnage - Joy: Interested
Bentley R-Type - Amy: Interested
Bentley Mk 6 - Ruth: Interested
Bentley S1 - Emily: Interested
Continental - Goddess: Interested
Lagonda - Grace: Interested
- - - - Other Information - - -
Good site! <a href=htttp://play-online-k
- - - - Enquiry Source Wedding
--------------------------
My code is as follows
<script>
<!--
function validate(form) {
if (form.firstName.value.leng
{
alert("Please enter your first name.")
form.firstName.focus()
return false
}
if (form.lastName.value.lengt
{
alert("Please enter your last name.")
form.lastName.focus()
return false
}
if (form.email.value.length == 0)
{
alert("Please enter your e-mail address.")
form.email.focus()
return false
}
if (form.email.value.indexOf(
{
alert("Please enter a valid e-mail address.");
form.email.focus();
return false;
}
if (form.selectDay.value == 0)
{
alert("Please Enter a Day.")
form.selectDay.focus()
return false
}
if (form.selectMonth.value == 0)
{
alert("Please Enter a Month.")
form.selectMonth.focus()
return false
}
if (form.selectYear.value == 0)
{
alert("Please Enter a Year.")
form.selectYear.focus()
return false
}
if (form.transType.value == "Please Select Usage")
{
alert("Please Select Transport For.")
form.transType.focus()
return false
}
if (form.requiredFor.value == "Please Select")
{
alert("Please Choose Required For Section.")
form.requiredFor.focus()
return false
}
if (form.collectionTown.value
{
alert("Please the Initial Collection Point.")
form.collectionTown.focus(
return false
}
}
//-->
</script>
PLEASE help here and understand that I do not know anything about java
Many thanks
Ashley
You can change alert(form.elements[i].val ue); to a message you want to display, such as
alert("No URL links allowed");
alert("No URL links allowed");
You're in the wrong TA actually. You need JavaScript. Use regular expressions that match urls. Plenty of them on the Web
Yes. it is a better way to use reg expression because it is more flexible and case-insensitive.
function validate(form) {
for (var i = 0; i<form.length; i++)
{
if(form.elements[i].value. match(/http:/gi) ){
alert("No URL links allowed");
form.elements[i].focus();
return false;
}
}
...
...
function validate(form) {
for (var i = 0; i<form.length; i++)
{
if(form.elements[i].value.
alert("No URL links allowed");
form.elements[i].focus();
return false;
}
}
...
...
ASKER
Thank you to both. So if I just add the following above each form element
for (var i = 0; i<form.length; i++)
{
if(form.elements[i].value. indexOf("http: ") >= 0){
alert(form.elements[i].val ue);
form.elements[i].focus();
return false;
}
}
Will this solve the problem?
Since I posted this yesterday I've received 16 of these foolish junk emails. What I can't understand is what use can these ever be as they will not create link of any use?
Ashley
for (var i = 0; i<form.length; i++)
{
if(form.elements[i].value.
alert(form.elements[i].val
form.elements[i].focus();
return false;
}
}
Will this solve the problem?
Since I posted this yesterday I've received 16 of these foolish junk emails. What I can't understand is what use can these ever be as they will not create link of any use?
Ashley
I would include "mailto:" as well perhaps
>>What I can't understand is what use can these ever be as they will not create link of any use?
Could be being done by bots, which wouldn't necessarily understand that's the case
>>What I can't understand is what use can these ever be as they will not create link of any use?
Could be being done by bots, which wouldn't necessarily understand that's the case
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Owen. That's worth 100000 points. Many thanks for that.
Ashley
Ashley
jezella - can you tell me why you ignored my contributions?
ASKER
CEHJ Sorry that was an oversight. Generally, I thank all by name as all contributions are more than welcome and often helpful. In the case of Owen's answer, what was provided here was just a matter of copy and paste resulting in a complete answer. Very sorry to have hurt your feelings.
Jezella
Jezella
Try to add a block of code into your function, like this:
function validate(form) {
for (var i = 0; i<form.length; i++)
{
if(form.elements[i].value.
alert(form.elements[i].val
form.elements[i].focus();
return false;
}
}
if (form.firstName.value.leng
{
alert("Please enter your first name.")
form.firstName.focus()
return false
}
...
...
...