November 20th, 2010, 08:57 AM
Validate via JS or PHP??
Hello again. Please check the forth post. It's true, I personally prefer it if the errors I got were placed in the areas where the error occured INSTEAD of getting a popup box for every error. It's annoying.
HOWEVER, that very same post suggested the use of js over php for 'most' of the validation.
So which is the better way?
Here's my registration form:-
I have 5 textboxes
username: verify it doesn't exist, 4-20 chars, and no symbols except _
password: 2 txt boxes for pass to make sure they match, no symbols, and 4-20 chars
email: 2 txt boxes for email to make sure they match, email isn't previously registered, 8-50 chars, and no symbols except @ _ .
verifying username and email existence will be done via php. but what about the others? I still feel php is better but at the same time, and this is just humble knowledge, why let the server do all the work when i can let the client handle it? registration is no biggy i no but honestly, i'm looking for the RIGHT way to do this
November 20th, 2010, 02:12 PM
There is a third option, which was relatively unknown ten years ago: use Ajax. It's a more fluid use of the two languages.
As an aside, be sure to note the dates of articles you read online. The one you linked to wasn't necessarily outdated, but there is a lot of outdated material floating around the Web.
Soldiers, from the height of these pyramids forty centuries look down upon you.
▪ Napoleon, on the eve of the Battle of the Pyramids
November 20th, 2010, 02:29 PM
duely noted. tho i must confess to not having the confidence to take on a third language. yes perhaps i didnt express or phrase what i learned from that post properly but i do agree with what you said about using both language and the uses of each.
so im on the right track. checking if username and email exist via php and checking for empty values via js has been taken care of already before i created this topic. all that's left is, length of each entry, regex for username, email, pass, and see if email entries and pass entries each match together.
now im not sure if i should take ur words literally because if i did then the above 3 tasks are to be taken care of via js. but i just cant imagine alert boxes popping up the entire time to a user. im looking back at when i registered in a site or forum and i recall that the errors always appeared right above the form. mayb they do everything with php. or mayb its ajax that does this. ack what should i do >.<
EDIT: i decided ill go all out on php. except the empty values. this is the 3rd time i edit this post. cant make up my mind. but i really do believe that seeing error messages printed on the screen next to the errors is a lot better than constant alerts popping up on the screen. someone back me up here or telling exactly what to do. gotta do it right..
November 20th, 2010, 04:13 PM
November 20th, 2010, 04:18 PM
wow for real? u want me to do all the checks with both languages? im not complaining. just making sure. u want me to do all the checks with both languages
ill do it. ty again for the help.
November 21st, 2010, 07:20 PM
i had the values verified via js and php. question is, how do i tell the app to verify via php IF js was disabled? I found the noscript tag but i dont think it helps enough.
login page has the button FORGOTPASS. when i click it, forgotpass.php gets included in login.php. when i enter my email in forgotpass.php and press submit, getpass.php gets included in forgotpass.php.
the noscript tag displays the same content that a js enabled browser does for a user. but i also read something about cloaking and how google banned it. SO, im thinking the only solution would be to write this:
or is that cloaking too? -_-
HONESTLY? im kinda thinking i ignore the fact that some users dont have js enabled, delete the verifying functions of php and just include getpass.php where it looks for it in the db then returns result.
November 22nd, 2010, 01:57 AM
You don't, you validate with both regardless.
Originally Posted by wildheart25c
Last edited by Winters; November 22nd, 2010 at 05:55 AM.
November 25th, 2010, 02:20 PM
ok im at the part where i upload a pic. i performed the usual pic checks via php. tried looking for a way to do it with js and this is the first result i found site
the html code is missing. had to open source file. i copied it. didnt work. this line confuses me ==> onChange="onchange="img.src=document.form1.image.value">
anyways when i try it on the site it works. but after copying the code and trying it out, it didnt work. what am i missing here? i think it's that line thats messing it up for me. but if thts the case, whyd id it work for the site and not me?
EDIT: fixed it. check this out. changed the code a tiny bit http://www.chestysoft.com/jpegresize/jscfdemo.asp
November 26th, 2010, 12:30 AM
Ok i'm having a problem with the size/height width. first of all, whats the relation between the size and the dimensions? is there a formula or both are completely unrelated?
second question. this code always returns the height and width of w/e image i choose as 0. why?
var filename = document.form1.filesent.value;
var valid = true
var Img1 = new Image()
if (filename == '')
valid = false;
alert("Please include a file.");
extension = filename.substring(filename.length - 3, filename.length);
if (extension.toUpperCase() != 'JPG')
valid = false;
alert("The file must be a JPG.");
Img1.src = filename;
if ((Img1.height == 0) || (Img1.width == 0))
valid = false;
alert("The file is invalid.");
document.form1.height.value = Img1.height;
document.form1.width.value = Img1.width;
// End -->
<form method="post" enctype="multipart/form-data" name="form1" onSubmit="return CheckUpload()">
<input type="hidden" name="height" value="0">
<input type="hidden" name="width" value="0">
<input type="file" name="filesent">
<input type="submit" value="Send File">