473,473 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

form validation using htmlspecialchars

72 New Member
hi guys,

I am writing a page to update database. I have being told to always scan every form input with functions trim(), htmlspecialchars() and stripslashes(). I don't know how to use these functions in javascript code. I have a javascript function 'checkForm'.

In the code below lines 11, 12, 13 don't work. Is it because eg stripslashes() is not a javascript function? What should I do to scan for corrupt input?

Thanks in advance



Here is my code

Expand|Select|Wrap|Line Numbers
  1. <form name="forms" method="post" onsubmit="return checkForm();" action="proc.php" id="myForm">
  2.  
  3. <script language="JavaScript">
  4. function checkForm()
  5. {
  6.   var cName;
  7.   with(window.document.myForm) {
  8.     cName = tbxName;
  9.   }
  10.  
  11.   cName.value = trim(cName.value);
  12.   cName.value = stripslashes(cName.value);
  13.   cName.value = htmlspecialchars(cName.value);
  14.  
  15.   if (some test) {
  16.     alert("invalid name");
  17.     cName.focus();
  18.     return false;
  19.   }
  20. }
  21. </script>
  22.  
  23. <input name="Name" type="text" id="tbxName" style="width:140px" class="textbox" />
  24.  
  25.  
  26. </form>
  27.  
May 14 '14 #1
1 2187
gits
5,390 Recognized Expert Moderator Expert
the methods you want to use are php-functions. if you want to use such methods clientside for input-modification then you have to reimplement them with the replace() method or using regExp for that purpose. besides that - its not safe to do those modifications clientside if you want to ensure that its always done before updating the DB with the values - you should use those methods in the php-code on the serverside.
Jun 6 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: n3mtkj3mzsir0cy | last post by:
I have created web pages that do client-side form validation using the onclick directive. E.g., <form action=other_page.cgi method=post> Enter your age: <input name=age> <input type="submit"...
2
by: daniel.boorn | last post by:
Form validation using JavaScript has never been as easy and simple! We have developed a free generic form validation script that can validate any form with very little JavaScript required in form!...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
2
by: nbt725 | last post by:
Dear Sir, Hello ! I need to validate my login form which is displayed using <div> to give sliding effect and not to refresh page, hence can't use generic php submit but to validate using...
1
by: printline | last post by:
Hello All I'm a newbee to javascript/ajax. I have produced a form, where i want to do some validation on some fields. I have used the spry framework and it works fine. Now, i have a select...
3
rizwan6feb
by: rizwan6feb | last post by:
Hi, everyone! I am learning AJAX these days. I want to validate a form with Ajax in such a way that every field is validated on the "onBlur" event. There are fields like Username, First Name, Last...
2
by: Sudhakar | last post by:
hi i need to validate a field in a form where a user enters their lodgement number as part of a registration form. this lodgement number can have letters, numbers, spaces and special characters....
7
by: DDragon | last post by:
I have a couple of forms, at the moment im using JS to validate them, but i would prefer to use PhP but im not quite sure about how to set up validation with it. If anyone can point me in the right...
4
by: ghjk | last post by:
I' developing web site with php and postgres. I want to validate php forms using ajax. I'm new to ajax and tried to several examples. But still I couldn't get it. Could someone please tell me a...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.