SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    advanced php/js form question

    ok, I have a situation where I need to get some information out of a dynamically loaded java applet... long story short, that java applet is able to spit out some javascript when it fires up, so it creates a js object containing arrays of the values for each of several printable areas, like:
    Code:
    var printAreas = new Object();
    printAreas.name = [ 'front','back','l-sleeve','r-sleeve','collar','cuffs','pocket'];
    printAreas.label = [ 'Front','Back','Left Sleeve','Right Sleeve','Collar','Cuffs','Pocket'];
    printAreas.printable =[1,1,1,1,0,0,1];
    printAreas.centerLine = [ 365,330,270,270,0,0,60];
    that's the easy part. Now I need to take that object and turn it into form elements. For each print area, I need similar form inputs... each one gets a name, label, etc. the same as the others, along with a few additional inputs for info that isn't in the object. I can build the form on the fly using mootools, but I don't know the proper way to set up the form... I've never set up a form that contained multiple groups of similar fields like this.

    So, to summarize, I will have multiple print areas, won't know in advance how many there are, and each will have the same field names. How can I design the form so that I can evaluate each print area? Can I use named fieldsets to separate them maybe? Can php/xhtml forms deal with that kind of situation, or do I have to build some JS to evaluate the form?

    thanks in advance for any advice...

  2. #2
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you go along the lines of

    <input name="name[]" value="front">
    <input name="name[]" value="back">
    <input name="name[]" value="l-sleeve">

    Im at work right now so cant test it, but maybe someone else will confirm!

  3. #3
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by taliesinnz View Post
    I think you go along the lines of

    <input name="name[]" value="front">
    <input name="name[]" value="back">
    <input name="name[]" value="l-sleeve">

    Im at work right now so cant test it, but maybe someone else will confirm!
    That is correct. The input fields are then handled as arrays.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

  5. #5
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can't be... that's way too easy

    Thanks very much to both of you

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yah, PHP will parse the [] and structure the resultant POST data as arrays, which you can iterate over and validate/process with a unknown number of elements.

    I think of the different fields as "aligned arrays", though I don't know if anyone else uses the term.
    E.g $_POST['name'][3] is the name corresponding to the qty for $_POST['qty'][3]


Bookmarks

Posting Permissions

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