www.webdeveloper.com
Results 1 to 6 of 6

Thread: Collecting Dynamic Form Data With PHP

  1. #1
    Join Date
    Mar 2008
    Location
    Leeds
    Posts
    26

    Collecting Dynamic Form Data With PHP

    Howdy,

    I'm creating a dyamic from like this:

    for ($zi=1; $zi<=$RowNumber; $zi++){
    echo "<br class=\"clear\"/> <label for=\"ticketREF" . $zi. "\" class=\"label\">Ticket Ref (" . $zi . ") :</label>";
    echo "<input type=\"text\" id=\"ticketREF" . $zi. " name=\"ticketREF" . $zi. "\" class=\"label\">";
    }


    $RowNumber is an integer determined by a database and could be any value larger than 0. Now when I want to collect the dynamic form I know in classic ASP I can do something like this (I've passed $Rownumber to the server using $_POST)

    for ($zj=1; $zj<=$RowNumber; $zj++){
    $var = "ticketREF" . $zj;
    $thisTextbox = $_REQUEST[$var];
    echo $thisTextbox . "<br />";
    }


    Why won't this collect the $_Request data?

    Any ideas anyone?

  2. #2
    Join Date
    Jul 2007
    Posts
    48
    Instead of $_REQUEST try using $_GET or $_POST depending on your form submission type. Just a guess, might help?

  3. #3
    Join Date
    Mar 2008
    Location
    Leeds
    Posts
    26
    Tried it - no joy. Downer!

  4. #4
    Join Date
    Jul 2007
    Posts
    48
    Hmm, try print_r($_REQUEST) to see what is being sent through?

  5. #5
    Join Date
    Mar 2008
    Location
    Leeds
    Posts
    26

    Sorted!!!!

    You know your onions - the problem was that I hadn't closed a quote mark on the form

    this

    echo "<input type=\"text\" id=\"ticketREF" . $zi. " name=\"ticketREF" . $zi. "\" class=\"label\">\n";

    should be this

    echo "<input type=\"text\" id=\"ticketREF" . $zi. "\" name=\"ticketREF" . $zi. "\" class=\"label\">\n"

    Thanks! Thanks! Thanks!

    I've been looking at that for over an hour!!!!

  6. #6
    Join Date
    Jul 2007
    Posts
    48
    Easily done !

    Don't forget, you can include variables like this to keep you code less cluttered...

    PHP Code:
    echo "<input type=\"text\" id=\"ticketREF$zi\" name=\"ticketREF$zi\" class=\"label\">\n" 
    Doesn't work if you're using single quotes to define the string though

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles