Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts

    server side or client side validate?

    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.

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by NancyJ View Post
    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

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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).
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New Coder
    Join Date
    May 2007
    Location
    Provo, UT - for now...
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #8
    New Coder
    Join Date
    May 2007
    Location
    Provo, UT - for now...
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cbsturg View Post
    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.

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    You have to have a delay. Try this:
    Code:
    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.
    }

  • #11
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    You have to have a delay. Try this:
    Code:
    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.

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Try this:
    Code:
    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);   
      }  
    }

  • #13
    Regular Coder
    Join Date
    Nov 2005
    Posts
    148
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Try this:
    Code:
    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?

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Have you actually tried the code? Do you have a link to the page?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •