Auto generate text boxes for submission

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blindaviator
    New Member
    • Jun 2010
    • 5

    Auto generate text boxes for submission

    I am trying to setup a webpage in PHP to auto generate a table filled with text boxes for a form submission..

    Is this possible to do in PHP??

    Basically what I need to do is have a main page that asks 2 questions.. Question 1 is how many rows and question 2 is how many columns and when you hit submit it generates the table filled with text boxes that can be filled in with values and added together and then submitted to a SQL database.

    I am rather new to PHP and am unsure if this is possible? I have searched the web and haven't been able to find anything
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Yes this is possible.

    What code have you attempted?

    Do you know how to work with posted variables in PHP?

    Do you know how loops work?

    Is your MySQL database setup and can you connect to it with PHP code?

    Comment

    • blindaviator
      New Member
      • Jun 2010
      • 5

      #3
      Originally posted by dlite922
      Yes this is possible.

      What code have you attempted?

      Do you know how to work with posted variables in PHP?

      Do you know how loops work?

      Is your MySQL database setup and can you connect to it with PHP code?
      I am still pretty new to PHP and learning... I have some code somewhat similar to this setup now that pulls tables from the database and drops it all into a dynamically generated table... Am assuming this will be similar..

      I haven't attempted any code yet as I am still unsure how to begin creating it... I have been looking at some samples of code from other sites but all of them want to mix javascript in with it and I would rather stick with PHP... The data integrity must remain server-side if possible to help prevent highjacking of the data and manipulation..

      I know a little about variables and arrays...

      Loops I know... They are relatively easy...

      I have a small simple CMS I have setup just to maintain users for this site... Yes it uses MYSQL...
      It is likely that I will setup a separate database to hold the data generated within this particular code...

      Most of my issues so far with generating code is trying to remember all the rules for formatting... I have the basics down of PHP (so far)...

      Comment

      • anfetienne
        Contributor
        • Feb 2009
        • 424

        #4
        hi,

        you need to go to this link and scroll down... this will show you how to generate rows... you could use it as a base to work from on you loops.




        also the part where it says the code below... the number "4" is the amount of columns it will echo into your page so however many columns is filled in your form will have to be placed there

        Code:
        if ($i == 4){
        echo '</tr>';
        $i = 0;
        }
        Last edited by anfetienne; Jun 14 '10, 05:23 PM. Reason: adding extra info

        Comment

        • blindaviator
          New Member
          • Jun 2010
          • 5

          #5
          Originally posted by anfetienne
          hi,

          you need to go to this link and scroll down... this will show you how to generate rows... you could use it as a base to work from on you loops.




          also the part where it says the code below... the number "4" is the amount of columns it will echo into your page so however many columns is filled in your form will have to be placed there

          Code:
          if ($i == 4){
          echo '</tr>';
          $i = 0;
          }
          Hey I appreciate the link...

          That one looks like it is pulling info from a database to display it... What I am trying to do is different but it gives me a good idea of what I need to do...

          Any and all help is appreciated...

          Comment

          • blindaviator
            New Member
            • Jun 2010
            • 5

            #6
            The one I found which is very close to what I need is this but it uses javascript and it doesn't generate tables:

            Code:
            <html>
            <head>
                 <script>
                  function create_input_boxes()
                  {
                   if(document.getElementById("name0")){return true;}
                  var boxes="";
                 var num_boxes=document.getElementById("num_boxes").value;
                  if(num_boxes)
                  {
                   for(var i=0;i<num_boxes;i++)
                   {
                    boxes+="<input id='name"+i+"' name='name"+i+"' value=''><br />";
                    }
                   document.getElementById("textbox_container").innerHTML=boxes;
                   }
                   return false;
                   }
                 </script>
                 </head>
                <body>
                 <form id="theForm" action="#" method="post" onsubmit="return create_input_boxes();">
                 <div id="textbox_container"></div>
                 Enter number input boxes: <input name="num_boxes"><br />
                 <div id="submit_button"><input type="submit" name="submit" value="Submit"></div>
                 </form>
                 <?php
                 if(isset($_POST["submit"]))
                 {
                  for($i=0;$i<count($_POST);$i++)
                  {
                   $name[]=!empty($_POST["name".$i])?$_POST["name".$i]:""; // All dynamically created inputs are being stored again in $name array
                  }
                  for($i=0;$i<count($name);$i++)
                  (
                   echo $name[$i]."<br />";
                   }
                  }
                ?>
                  </body>
                  </html>

            Comment

            • anfetienne
              Contributor
              • Feb 2009
              • 424

              #7
              Originally posted by blindaviator
              Hey I appreciate the link...

              That one looks like it is pulling info from a database to display it... What I am trying to do is different but it gives me a good idea of what I need to do...

              Any and all help is appreciated...
              it can be used without pulling data from a DB... you minus the top loop and take off the last bracket, use a for loop instead of if loop it may help... make $i the post data for the rows and then use the post data for the column where the number 4 is.... that's all

              Comment

              • blindaviator
                New Member
                • Jun 2010
                • 5

                #8
                Originally posted by anfetienne
                it can be used without pulling data from a DB... you minus the top loop and take off the last bracket, use a for loop instead of if loop it may help... make $i the post data for the rows and then use the post data for the column where the number 4 is.... that's all
                Ok I will look into that then... Much appreciated

                Comment

                Working...