Jump to content

repost new row in Multi form wizard


RJ2001

Recommended Posts

I have a javascript function that adds a new row to an existing php form. The form has two stages and saves all data from each stage in a session for each variable. I have a counter to remember the count of each new row that is dynamically added.

 

My question is how can I save these rows once they are created so that they will still be there once I come back to that stage of the form, i.e. I go back to step one to change something when I hit next all the rows that I created are still there and have the data from the php session.

 

Code is below

 

<Javascript to add new row>

 


<SCRIPT LANGUAGE="JavaScript">

// Include the function to add a row
function HDonCallReport_addCallsRecieved()
{
var tbody = document.getElementById('CallsReceived').getElementsByTagName("TBODY")[0];
var row = document.createElement("TR"); // create a new table row
var td = new Array(4); // counting the table we made there are 8 cells per table row
var tempSelect;
var tempInput;
var rownum = tbody.rows.length; // not +1 because we have a header row


var T = document.getElementById("Time_" + rownum);
var sT = "selectTime(this,Time_#num#);";
var sT2 = sT.replace( /#num#/g, ""+rownum);

// Create Time select box
td[0] = document.createElement("TD"); // create a td element  
tempInput = document.createElement("INPUT"); //  create an input
tempInput.name = "Time_" + rownum; // name the input
tempInput.id = "Time_" + rownum; // give an id to the input
tempInput.size = 20; // set the size of the input
tempInput.onblur = function() {validateTimePicker(this);};
tempInput.setAttribute('value', "<?php echo htmlentities($_POST['Time_' + rownum]); ?>") ;

td[0].appendChild(tempInput); // add the select box to the table cell

var tempImg = document.createElement('img');
tempImg.src = 'gif/timepicker.gif';
tempImg.alt = 'timepicker';
tempImg.align = 'top';
tempImg.hspace = '5' //for IE to put space between image and input field.
tempImg.onclick = function() {selectTime(this, document.getElementById("Time_" + rownum));};
tempImg.style.cursor = "hand";
td[0].appendChild(tempImg);

// Create Location input
td[1] = document.createElement("TD"); // create a table cell
tempInput = document.createElement("INPUT"); //  create an input
tempInput.name = "Location_" + rownum; // name the input
tempInput.id = "Location_" + rownum; // give an id to the input
tempInput.size = 30; // set the size of the input
td[1].appendChild(tempInput); // add the input to the table cell

// Create Who Called input
td[2] = document.createElement("TD");
tempInput = document.createElement("INPUT");
tempInput.name = "WhoCalled_" + rownum;
tempInput.id = "WhoCalled_" + rownum;
tempInput.size = 30;
td[2].appendChild(tempInput);

// Create Response input
td[3] = document.createElement("TD");
tempInput = document.createElement("textarea");
tempInput.name = "Response_" + rownum;
tempInput.id = "Response_" + rownum; 
tempInput.rows = 2;
tempInput.cols = 30;
td[3].appendChild(tempInput);

           
// Append each cell to  the row we created row
for(i=0; i<4; i++)
  row.appendChild(td[i]);
// Append row to table so that it appears on screen
tbody.appendChild(row);

// Increment the number of Code rows
//document.CallsReceived.CodeCount1.value = parseInt(document.CallsReceived.CodeCount1.value) + 1;
var ccObject;
    ccObject=document.getElementById('HDonCallReport_CodeCount1');
    ccObject.value=parseInt( ccObject.value ) + 1;
};

// Include the function to delete a row - force them to have at least one row (i.e cannot delte only row)
function HDonCallReport_deleteCallsReceived()
{
var tbody = document.getElementById('CallsReceived').getElementsByTagName("TBODY")[0];
form = document.CallsReceived; // Timesheetform is the name of your form
if(tbody.rows.length > 2) // +1 because we don't count header row
{
	tbody.deleteRow(tbody.rows.length-1);
  	// Decrement the number of Codes
 	 //document.CallsReceived.CodeCount1.value = parseInt(document.CallsReceived.CodeCount1.value) - 1;
 	var ccObject;
     	ccObject=document.getElementById('HDonCallReport_CodeCount1');
     	ccObject.value=parseInt( ccObject.value ) - 1;
}
else
{
  alert('There must be at least one row for calls received.  Tip: Write "None" and the current time if there were no calls. (All boxes must be completed)');
}
};

</script>

 

 

Partial PHP

 

<!--<meta http-equiv="refresh" content="5;url=home.php"> -->
	<?php
		}

		else
		{
			//if the form has been submitted
			if(isset($_POST['submit']))
			{				
				//another check to see if the form has been submitted
				if($_POST['submit'] == 1)
				{
					//save the user's choices from the first form						
					$_SESSION['McFrAckRA1'] = $_POST['McFrAckRA1'];
					$_SESSION['McFrAckRA2'] = $_POST['McFrAckRA2'];
					$_SESSION['McFrAckCheckIn'] = $_POST['McFrAckCheckIn'];
					$_SESSION['McFrAckMidCheck'] = $_POST['McFrAckMidCheck'];
					$_SESSION['McFrAckCheckOut'] = $_POST['McFrAckCheckOut'];
					$_SESSION['MontRA1'] = $_POST['MontRA1'];		
					$_SESSION['MontRA2'] = $_POST['MontRA2'];
					$_SESSION['MontCheckIn'] = $_POST['MontCheckIn'];	
					$_SESSION['MontMidCheck'] = $_POST['MontMidCheck'];
					$_SESSION['MontCheckOut'] = $_POST['MontCheckOut'];	
					$_SESSION['TateRA1'] = $_POST['TateRA1'];
					$_SESSION['TateRA2'] = $_POST['TateRA2'];	
					$_SESSION['TateCheckIn'] = $_POST['TateCheckIn'];
					$_SESSION['TateMidCheck'] = $_POST['TateMidCheck'];	
					$_SESSION['TateCheckOut'] = $_POST['TateCheckOut'];
					$_SESSION['HundleyRA'] = $_POST['HundleyRA'];	
					$_SESSION['HundleyCheckIn'] = $_POST['HundleyCheckIn'];
					$_SESSION['HundleyMidCheck'] = $_POST['HundleyMidCheck'];	
					$_SESSION['HundleyCheckOut'] = $_POST['HundleyCheckOut'];
					$_SESSION['SouthSideRA'] = $_POST['SouthSideRA'];	
					$_SESSION['SouthSideCheckIn'] = $_POST['SouthSideCheckIn'];
					$_SESSION['SouthSideMidCheck'] = $_POST['SouthSideMidCheck'];
					$_SESSION['SouthSideCheckOut'] = $_POST['SouthSideCheckOut'];
					$_SESSION['RadioCheck'] = $_POST['RadioCheck'];
					$_SESSION['CampusTone'] = $_POST['CampusTone'];
					//if we are on the second step display the form
					if($_GET['step'] == 2)
					{		
	?>
						<h2>Step 2 of 2<br /><br />
							<form action="OnCallReport.php?step=1" id="step2" method="post" name="step2" onSubmit="" />
								<input type="hidden" value="<?php echo htmlentities($_POST['McFrAckRA1']); ?>" name="McFrAckRA1" />
								<input type="hidden" value="<?php echo htmlentities($_POST['McFrAckRA2']); ?>" name="McFrAckRA2" />
								<input type="hidden" value="<?php echo htmlentities($_POST['McFrAckCheckIn']); ?>" name="McFrAckCheckIn" />
								<input type="hidden" value="<?php echo htmlentities($_POST['McFrAckMidCheck']); ?>" name="McFrAckMidCheck" />
								<input type="hidden" value="<?php echo htmlentities($_POST['McFrAckCheckOut']); ?>" name="McFrAckCheckOut" />
								<input type="hidden" value="<?php echo htmlentities($_POST['MontRA1']); ?>" name="MontRA1" />
								<input type="hidden" value="<?php echo htmlentities($_POST['MontRA2']); ?>" name="MontRA2" />
								<input type="hidden" value="<?php echo htmlentities($_POST['MontCheckIn']); ?>" name="MontCheckIn" />
								<input type="hidden" value="<?php echo htmlentities($_POST['MontMidCheck']); ?>" name="MontMidCheck" />
								<input type="hidden" value="<?php echo htmlentities($_POST['MontCheckOut']); ?>" name="MontCheckOut" />
								<input type="hidden" value="<?php echo htmlentities($_POST['TateRA1']); ?>" name="TateRA1" />
								<input type="hidden" value="<?php echo htmlentities($_POST['TateRA2']); ?>" name="TateRA2" />
								<input type="hidden" value="<?php echo htmlentities($_POST['TateCheckIn']); ?>" name="TateCheckIn" />
								<input type="hidden" value="<?php echo htmlentities($_POST['TateMidCheck']); ?>" name="TateMidCheck" />
								<input type="hidden" value="<?php echo htmlentities($_POST['TateCheckOut']); ?>" name="TateCheckOut" />
								<input type="hidden" value="<?php echo htmlentities($_POST['HundleyRA']); ?>" name="HundleyRA" />
								<input type="hidden" value="<?php echo htmlentities($_POST['HundleyCheckIn']); ?>" name="HundleyCheckIn" />
								<input type="hidden" value="<?php echo htmlentities($_POST['HundleyMidCheck']); ?>" name="HundleyMidCheck" />
								<input type="hidden" value="<?php echo htmlentities($_POST['HundleyCheckOut']); ?>" name="HundleyCheckOut" />
								<input type="hidden" value="<?php echo htmlentities($_POST['SouthSideRA']); ?>" name="SouthSideRA" />
								<input type="hidden" value="<?php echo htmlentities($_POST['SouthSideCheckIn']); ?>" name="SouthSideCheckIn" />
								<input type="hidden" value="<?php echo htmlentities($_POST['SouthSideMidCheck']); ?>" name="SouthSideMidCheck" />
								<input type="hidden" value="<?php echo htmlentities($_POST['SouthSideCheckOut']); ?>" name="SouthSideCheckOut" />
								<input type="hidden" value="<?php echo htmlentities($_POST['RadioCheck']); ?>" name="RadioCheck" />
								<input type="hidden" value="<?php echo htmlentities($_POST['CampusTone']); ?>" name="CampusTone" />

								<table style="border: 1px solid #A42224;" width="100%" id="CallsReceived">
									<b><p><font size="3" color="Black">Calls Received:</font></p></b>				  
								    <tr>
								      <td > <b>Time</b></td>
								      <td > <b>Location</b></td>
								      <td > <b>Who Called</b></td>
								      <td ><b>Response</b></td>
								    </tr>		
								    
									<tr>
								    	<td >
								      		<input id="Time_1" name="Time_1" size="20" value="<?php echo htmlentities($_POST['Time_1']); ?>" onblur="validateTimePicker(this)" />
								      		<img src="gif/timepicker.gif" align="top" onclick="selectTime(this,document.getElementById('Time_1'));" STYLE="cursor:hand" />
								      	</td>
								      	<td >
								      		<input id="Location_1"" name="Location_1" size="30" value="<?php echo htmlentities($_POST['Location_1']); ?>"  />
								      	</td>
								      	<td >
								      		<input id="WhoCalled_1" name="WhoCalled_1" size="30" value="<?php echo htmlentities($_POST['WhoCalled_1']); ?>" />
								      	</td>
								      	<td >
								      		<textarea rows="2" id="Response_1" name="Response_1" cols="30" /><?php echo htmlentities($_POST['Response_1']); ?></textarea>
								      	</td>
								    </tr>

								</table>
								<tr>
								    	<input type = "hidden" id = "HDonCallReport_CodeCount1" name= "HDonCallReport_CodeCount1" value= "1">
								    
										<a href="#" onclick="HDonCallReport_addCallsRecieved(); return false">Add Another Call</a>
										 
										<a href="#" onclick="HDonCallReport_deleteCallsReceived(); return false">Delete Last Row</a>					    
								</tr>

									<br /> <br />

								<table style="border: 1px solid #A42224;" width="100%">
									<tr>
								  		<td align="center">
								  			Final Comments for the Evening: 
								  		</td>
								  		<td>
								  			<textarea rows="4" name="FinalComments" cols="40"><?php echo htmlentities($_POST['FinalComments']); ?></textarea>
								  		</td>
								  		<td>
								  			ORL Follow-up (if Necessary): 
								  		</td>
								  		<td>
								  			<textarea rows="4" name="ORLFollowUp" cols="40"><?php echo htmlentities($_POST['ORLFollowUp']); ?></textarea>
								  		</td>
									</tr>
								</table>

								<table align="right" width="100%">
									<tr>
										<td>
											<p align="right">
												<input type="submit" value="Previous" />
												<input type="button" value="Finish" title="Click here to review form" onclick="submitForm();" />
											</p>
										</td>
									</tr>
								</table>

							</form>
						</h2>

	<?php
					}

				}
			}

			else
			{
	?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.