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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Validating Dynamic Forms

    Hello,

    First I would like to say that I am sorry for my poor topic title, however it is kind of hard to explain what I need help with.

    Recently I decided that I was going to make a settings wizard for the popular online ftp client, net2ftp. I was finding that many people who wanted to install net2ftp on their own server were having problems editing the .php files with the correct settings, causing it not to work. So, I had the idea of using a HTML page to type in the settings then generating the settings file based on their input.

    However, since the user is able to choose any number of for example allowed/banned ftp servers a dynamically generated form was needed. With a little bit of help, I cooked up a way of using an 'Add Anouther' button to add a new input.

    However the way that I did it is quite different from the ways that are normally used. I have all of the forms named the same (eg <input type="text" name="allowed_ftpservers[]" />. The [] at the end creates an array, which my server side script is able to work with.

    Take a look at the site for a better explanation. http://www.dcrez.co.uk/create/links/settings-auth.htm

    However this does cause problems for data validation on the client side, while my server side script does trip out the empty values, problems can still happen. For the allowed ftp_servers someone can type in 'ALL' as well as an FTP server and it will accept them. On the last input, if only one of the two fields are filled in then there will be either one more username than there is a root directory or the other wayround which can cause problems. I would also like to regxp the values before submitting, as it is normally faster.

    However, none of my normal data validation seems to work, as it is something to do with the array. Could anyone tell me how I would be able to client side data validation?

    I am sorry for my bad english and poor explanation, but take a look at the site and you will see what I mean. Thank you for any help that you can give me.

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone have any ideas? Or is it not possible?

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    I'm a little confused as to what you actually want to validate. Do want only one of the last two inputs to be completed? What do you want to do about the ALL and SomeServer fields? When you say your methods don't work, what do you actually mean? Do you mean that you can't access the array's? If so how have you tried accessing the arrays?

    Sorry I haven't an answer, but maybe with the answers to the above, I may be able to help out a bit
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #4
    Regular Coder
    Join Date
    Jan 2005
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, I should have explained it better.

    Normally I would do something like
    function IsNotNull(){
    if (document.formname.input1.value.length = 0){ //empty
    alert("You did not fill out the form");
    return false;
    }
    return true;
    }
    if you try that when the input name is input1[] you will get a pare error.

    Now, thanks to a bit of help, I have, with thanks to the onBlur(this) and focus(); I hade made it so that when the click off of the form field it will validate it, if it fails they get an alert box pop-up requiring them to leave it blank (and let the server remove the blanks) or type in a valid input, it will then focus(); them back on the field.

    Currently I am using simple RegExp to validate it, however there is a slight problem. If i do /w{1}/ it will look for one 'w', however if I type in ww, quite rightly it will find a match (two of em), I would like to know how I can get it to only pass if the entire string (input) return true, so ww would be false, but w would return true.

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by evilguru
    if you try that when the input name is input1[] you will get a pare error.
    i believe this issue has been covered only recently. hmmm ... what to search on to retrieve it, though.
    *keep it simple (TM)

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    don't put a number into the name of the field. just name it and it's sibllings as input[]. then refer to each as input[x] where "x" is number of the field in the array.
    *keep it simple (TM)

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Access field named allowed_ftpservers[] like this:

    var ftpFields = document.formname.elements['allowed_ftpservers[]'];

    Since there could be one or more fields with that name, you have to check if the returned object is a collection or not.
    Code:
    var ftpFields = document.formname.elements['allowed_ftpservers[]'];
    if (typeof ftpFields.length == "undefined")
    {
       //there's only one field
       alert(ftpFields.value);
    }
    else
    {
       //more than 1 field
       for (var i=0;i<ftpFields.length;i++){
          alert(ftpFields[i].value);
       }
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    Regular Coder
    Join Date
    Jan 2005
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, again, sorry if I am asking to many questions, or being annoying in any way, I do not mean to be.

    Now, currently I have been doing my matching like this.
    Code:
    	var emailreg = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    	if (emailreg.test(email)){
    	}
    This is one I use for checking email addresses, however, it seems to be different from how other people do theirs, so this could be the problem...

    Now, I have the problem that if my test value is aaa and my pattern is /a{1}/ it will return true (three times as there are three a's), however I would like to know to make it only return true if the entire string (aaa) passes, in which case 'aaa' would return false as would 'aa' (as there is more than one a) however 'a' would return true. As when you are validating ip addresses while the ip address might be valid (eg 192.168.0.1) ip address if they put somenthing like 'thisisnotvalidbutwhatareyougoingtodo192.168.0.1 would still return true, however I want the entire string to return true but thisisnotvalidbutwhatareyougoingtodo192.168.0.1 would return false. It might be a hard one, but I am sure that someone can help me


  •  

    Posting Permissions

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