Jump to content

How to insert mulitple forms into db


runnerjp

Recommended Posts

Hey guys i have a script below where i can add other input boxes if needed.... these are then numberd plusing 1 to each one.

 

How can i make sure they are all added to my db?

 

An output might look liek this

 

Array ( [date] => 1 [am] => 1 [pm] => 1 [comment] => 1 [date2] => w [am2] => w [pm2] => w [comment2] => w [date3] => 1 [am3] => 1 [pm3] => 1 [comment3] => 1 [date4] => g [am4] => g [pm4] => g [comment4] => g )

 

 

<script>  
        function addRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          var row = tbl.insertRow(lastRow);  
            
          var cell1 = row.insertCell(0);  
          var input = document.createElement('input');  
          input.name = 'date' + lastRow;  
          input.id = 'date' + lastRow;  
          cell1.appendChild(input);  
            
          var cell2 = row.insertCell(1);  
          input = document.createElement('input');  
          input.name = 'am' + lastRow;  
          input.id = 'am' + lastRow;  
          cell2.appendChild(input);  
            
          var cell3 = row.insertCell(2);  
          input = document.createElement('input');  
          input.name = 'pm' + lastRow;  
          input.id = 'pm' + lastRow;  
          cell3.appendChild(input);  
            
          var cell4 = row.insertCell(3);  
          input = document.createElement('input');  
          input.name = 'comment' + lastRow;  
          input.id = 'comment' + lastRow;  
          cell4.appendChild(input);  
        }  
          
        function delRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          if (lastRow > 2) tbl.deleteRow(lastRow - 1);  
        }  
    </script>  

<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform"> 
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" id="thetable">  
   <tbody>  
     <tr>  
       <td>  
         <p align="center">Date</p></td>  
       <td>  
         <p align="center">Am</p></td>  
       <td>  
         <p align="center">Pm</p></td>  
       <td>  
         <p align="center">Comment</p></td>  
    </tr>  
     <tr>  
       <td>  
        <input name="date" /> </td>  
       <td>  
        <input name="am" /> </td>  
       <td>  
        <input name="pm" /></td>  
       <td>  
        <input name="comment" /></td>  
    </tr>  
  </tbody>  
</table>  
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse">  
     <tr>  
       <td>  
       <p align="center">  
          <input type="button" value="Add Row" onclick="addRow()" />  
          <input type="button" value="Subtract Row" onclick="delRow()" />  
                </p>  
       </td>  
    </tr>  
</table>

Link to comment
https://forums.phpfreaks.com/topic/194501-how-to-insert-mulitple-forms-into-db/
Share on other sites

I guess I'm sorta confused on what you want to do?  If just to simply make sure, then do tests to make sure it's working...

 

But sure that is not what you are asking, so if you want to make sure if dynamically they are added for a script then with some creativity, do calls to the tables behind the scenes to open up the table and read the fields you just entered and display error message if not there is nothing there. Could write a function for that.... but as I said little lost on what you are asking so maybe this helps.

try to change your data array

<script>  
        function addRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          var row = tbl.insertRow(lastRow);  
            
          var cell1 = row.insertCell(0);  
          var input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][date]';  
          input.id = 'date' + lastRow;  
          cell1.appendChild(input);  
            
          var cell2 = row.insertCell(1);  
          input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][am]';  
          input.id = 'am' + lastRow;  
          cell2.appendChild(input);  
            
          var cell3 = row.insertCell(2);  
          input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][pm]';  
          input.id = 'pm' + lastRow;  
          cell3.appendChild(input);  
            
          var cell4 = row.insertCell(3);  
          input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][comment]';  
          input.id = 'comment' + lastRow;  
          cell4.appendChild(input);  
        }  
          
        function delRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          if (lastRow > 2) tbl.deleteRow(lastRow - 1);  
        }  
    </script>  

<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform"> 
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" id="thetable">  
   <tbody>  
     <tr>  
       <td>  
         <p align="center">Date</p></td>  
       <td>  
         <p align="center">Am</p></td>  
       <td>  
         <p align="center">Pm</p></td>  
       <td>  
         <p align="center">Comment</p></td>  
    </tr>  
     <tr>  
       <td>  
        <input name="data[1][date]" /> </td>  
       <td>  
        <input name="data[1][am]" /> </td>  
       <td>  
        <input name="data[1][pm]" /></td>  
       <td>  
        <input name="data[1][comment]" /></td>  
    </tr>  
  </tbody>  
</table>  
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse">  
     <tr>  
       <td>  
       <p align="center">  
          <input type="button" value="Add Row" onclick="addRow()" />  
          <input type="button" value="Subtract Row" onclick="delRow()" />
                </p>  
       </td>  
    </tr>  
</table>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.