I guess I should start by explaining better.
I have a form in which only part of the data needs to be sent to php so the popup for editing can open and build another form dynamically depending on what was entered in the main form. Then the user is returned to finish filling out the main form. This is how I accomplished that part.
ajax code in ticket.php:
Code: Select all
//var passing
// Get the HTTP Object
function getHTTPObject(){
if (window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest){
return new XMLHttpRequest();
}
else {
alert("Your browser does not support AJAX.");
return null;
}
}
// Not used here but deletion causes doWork() not to function
//need to figure out why so I can delete this part. Found this on the Internet
function setOutput(){
if(httpObject.readyState == 4){
document.getElementById('outputText').value = httpObject.responseText;
}
}
// Main function for getting and passing var
function doWork(ID){
httpObject = getHTTPObject();
if (httpObject != null) {
var httpObjectString = "../includes/ticketVarsInc.php?" + ID + "=";
httpObject.open("GET", httpObjectString + document.getElementById(ID).value, true);
httpObject.send(null);
/*next line commented out because only used for output
httpObject.onreadystatechange = setOutput;*/
}
}
var httpObject = null;
Submit button code in ticket.php:
Code: Select all
//calls ajax function and opens popup
<input type="button" value="add part numbers" onclick="doWork('equipQuantityAnalogConverter');doWork('equipQuantityDCT');
doWork('equipQuantityHDTVConverter');doWork('equipQuantityDVRService');popUp();"></input>
ticketVarsInc.php:
Code: Select all
<?php
session_start();
?>
<?php
/*collect and count equip quantities and place them in $HTTP_SESSION_VARS*/
if (isset($_GET['equipQuantityAnalogConverter'])){
$ACCount = $_GET['equipQuantityAnalogConverter'];
$HTTP_SESSION_VARS['ACCount'] = $ACCount;
}
if (isset($_GET['equipQuantityDCT'])){
$DCTCount = $_GET['equipQuantityDCT'];
$HTTP_SESSION_VARS['DCTCount'] = $DCTCount;
}
if (isset($_GET['equipQuantityHDTVConverter'])){
$HDTCount = $_GET['equipQuantityHDTVConverter'];
$HTTP_SESSION_VARS['HDTCount'] = $HDTCount;
}
if (isset($_GET['equipQuantityDVRService'])){
$DVRCount = $_GET['equipQuantityDVRService'];
$HTTP_SESSION_VARS['DVRCount'] = $DVRCount;
}
?>
<?php
/*collect data from ticketPopupInc.php*/
//This is where I need to get the data from the popup
//no way of the system knowing how many fields without using $ACCount to loop through the array
?>
ticketPopupInc.php:
Code: Select all
<?php
session_start();
?>
<html>
<head><title>Equipment Numbers</title>
</head>
<body>
<script type="text/javascript">
//This function not used at this point. Replace with ajax doWork function from ticket.php?
function submitForm(){
document.forms["equipForm"].submit();
}
function show_alert()
{
alert("Equipment Succesfully Added To Inventory!");
}
</script>
<form name="equipForm" id="equipForm" action="ticketVarsInc.php" method="POST">
<?php
/*get vars from session*/
$ACCounter = $HTTP_SESSION_VARS['ACCount'];
$DCTCounter = $HTTP_SESSION_VARS['DCTCount'];
$HDTCounter = $HTTP_SESSION_VARS['HDTCount'];
$DVRCounter = $HTTP_SESSION_VARS['DVRCount'];
/*layout form entries for equip#'s based on quantity from "ticket.php" form*/
echo '<table border="1px">';
if ($ACCounter != 0){
$ACFormCount = 0;
for ($i = 1; $i <= $ACCounter; $i++){
$ACFormCount++;
echo '<tr>';
echo '<td>';
echo 'Analog Converter ';
echo $i;
echo '</td>';
echo '<td>';
echo '<input type="text" size="25" maxlength="25" name="AC';
echo $i;
echo '"></input>';
echo '</td>';
echo '</tr>';
}
}
if ($DCTCounter != 0){
for ($i = 1; $i <= $DCTCounter; $i++){
$DCTFormCount++;
echo '<tr>';
echo '<td>';
echo 'DCT ';
echo $i;
echo '</td>';
echo '<td>';
echo '<input type="text" size="25" maxlength="25" name="DCT';
echo $i;
echo '"></input>';
echo '</td>';
echo '</tr>';
}
}
if ($HDTCounter != 0){
for ($i = 1; $i <= $HDTCounter; $i++){
$HDTFormCount++;
echo '<tr>';
echo '<td>';
echo 'HDT ';
echo $i;
echo '</td>';
echo '<td>';
echo '<input type="text" size="25" maxlength="25" name="HDT';
echo $i;
echo '"></input>';
echo '</td>';
echo '</tr>';
}
}
if ($DVRCounter != 0){
for ($i = 1; $i <= $DVRCounter; $i++){
$DVRFormCount++;
echo '<tr>';
echo '<td>';
echo 'DVR ';
echo $i;
echo '</td>';
echo '<td>';
echo '<input type="text" size="25" maxlength="25" name="DVR';
echo $i;
echo '"></input>';
echo '</td>';
echo '</tr>';
}
}
echo '</table>';
echo '<br />';
?>
<input type="button" value="Add" name="addNumbers" id="addNumbers" onclick="show_alert(); window.close();"></input>
</form>
</body>
</html>
As you can see the popup is created dynamically so there is no way once I submit it for the app to know how many fields were submitted to do the retrieval on the other end back in the ticketVarsInc.php page without using $ACCount, $DCTCount, $HDTCount, and $DVRCount as parameters in loops with arrays.
These are only 4 items out of 60 or 70 other items on the main ticket.php form so I don't want to use a regular submit at this point. The final submit button is at the end of the main form after all data is collected.
Everything works great up to this point so I just have to use ajax again to pass these fields into an array and then itterate through the array for my sql statement back in the ticketVarsInc.php page or in a seperate ticketFunctions.php page.
Maybe I can unset $_Get and then just reuse it the same way. Then count($_Get) should be an accurate count for building my sql query from?