...

View Full Version : server side or client side validate?



CstAn
05-14-2007, 06:26 PM
Dear all,

I had a import function which allow for user import data from excel file. The number of row was dynamic, mean that user may import hundred or data or may thousand of line.

should i perform client side or server side validate?

the problem i faced was if the import thousand of line, i need display out thousand of text (multiple by 6, cause 1 got 6 fields)

the take a lot of time to loading and cause browser "hang" (response slow)

any solution for me?

thanks.

NancyJ
05-14-2007, 08:49 PM
Usually I would say both but in this situation you have to server-side process it first anyway so I would say just server-side validation is fine.

CstAn
05-15-2007, 08:31 AM
Usually I would say both but in this situation you have to server-side process it first anyway so I would say just server-side validation is fine.

but it take so long time to process since the connection in corporate level was so slow.
one of issues i worry.

But if i using javascript, the browser will "hang" for 2 - 3 second or more
one of issues i worry.

anyone can teach me how can i display a frame that display the message to inform user when he/she click submit button, so that he/she will not close the browser?

I had use it, but it will wait the function(call for validate) finish execute jz display out.

*i put the function that display the message at top of function validate.

thanks

felgall
05-15-2007, 10:01 AM
You use client side validation to report errors to the person filling out the form immediately so as to save them time waiting for the server side validation. If it is going to take just as long to validate with JavaScript as the round trip to the server to do the necessary server side validation then the JavaScript becomes superfluous.

Server side validation needs to be done so that you know that the information entered was valid even for those visitors with JavaScript turned off.

Each serves a different purpose but the server side validation is ALWAYS needed.

Kor
05-15-2007, 12:06 PM
I agree with felgall. You need the server-side validation by all means. And use the client-side only if this one will take not too long (compared with the server-side one).

cbsturg
05-15-2007, 02:08 PM
You can easily create a hidden div that displays a notice to the user that their information is being validated. Once the user hits the upload button, the div is displayed and the information is validated.

As others have said, you cannot (well, you could - but at your own peril!) escape server-side validation, so you might as well just have them suck it up and wait. The best thing to do would be to go through your validation script and make sure that it's not unnecessarily cumbersome. That is, spend your time making the validation more efficient instead of worrying about running it client-side at the same time.

CstAn
05-16-2007, 06:55 AM
thank for reply.

I catch you all mean.

One more question:
how can i display a message each time a loop function finish execute?
In my side now, it just show the final loop result to user. the process did not show to user.

how can i do that?

cbsturg
05-16-2007, 01:22 PM
I'm not sure I quite get what you're asking. If you're running a server-side script, it's going to process all of the script before returning anything to the browser. Those "Loading, please wait" images you see on sites like Travelocity or Orbitz are just animated gif's that load on one page, and then the page with the server script that queries the database is called. So you see the image showing while it's loading another page.

If you're talking about running this loop with Javascript, that's a different issue altogether. The easiest way would be to create a div with an id and change its .innerHTML property after the execution of the loop.

CstAn
05-16-2007, 06:32 PM
I'm not sure I quite get what you're asking. If you're running a server-side script, it's going to process all of the script before returning anything to the browser. Those "Loading, please wait" images you see on sites like Travelocity or Orbitz are just animated gif's that load on one page, and then the page with the server script that queries the database is called. So you see the image showing while it's loading another page.

If you're talking about running this loop with Javascript, that's a different issue altogether. The easiest way would be to create a div with an id and change its .innerHTML property after the execution of the loop.

thanks.

what i plan to do:
for example in a loop:
for(i = 0; i < 100; ++i){
document.getElementById('result').innerHTML = "<p> record is == "+i+"</p>";

callOtherAjaxFunction(); //validate data entry with value in database.
}

when i == 0; it show "record is == 0" and then run the callOtherAjaxFunction();

when i == 1; it show "record is == 1" and then run the callOtherAjaxFunction();

and so on.

isn't possible to do like that?

what i do something is like a loading status msg that tell user what the system current doing.

I try out this function, but it only show when the loop finish execute. It will not show out the process of looping. although i delay the callOtherAjaxFunction(); to execute it only show out when the loop was finish execute.

glenngv
05-16-2007, 07:05 PM
You have to have a delay. Try this:


for(i = 0; i < 100; ++i){
setTimeout("document.getElementById('result').innerHTML='<p> record is == '+i+'</p>'", 500);

callOtherAjaxFunction(); //validate data entry with value in database.
}

CstAn
05-17-2007, 01:46 AM
You have to have a delay. Try this:


for(i = 0; i < 100; ++i){
setTimeout("document.getElementById('result').innerHTML='<p> record is == '+i+'</p>'", 500);

callOtherAjaxFunction(); //validate data entry with value in database.
}


i want display out the msg be4 the function execute. So, I try delay the callOtherAjaxFunction(). But the output will display only when the loop was finish executed.

This will not show out the loading msg and tell the user what the system do current.

glenngv
05-17-2007, 03:19 PM
Try this:

var ctr=0;
var timer;
function loading(){
if (ctr<100){
document.getElementById('result').innerHTML='<p> record is == '+ctr+'</p>';
callOtherAjaxFunction();
ctr++;
timer=setTimeout("loading()", 1000);
}
else{
clearTimeout(timer);
}
}

CstAn
05-17-2007, 03:26 PM
Try this:

var ctr=0;
var timer;
function loading(){
if (ctr<100){
document.getElementById('result').innerHTML='<p> record is == '+ctr+'</p>';
callOtherAjaxFunction();
ctr++;
timer=setTimeout("loading()", 1000);
}
else{
clearTimeout(timer);
}
}

this will display the msg "record is == 1" and so on...but it wont see the process running, jz the final result user will see.

rite?

glenngv
05-17-2007, 03:42 PM
Have you actually tried the code? Do you have a link to the page?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum