
December 29th, 2012, 04:41 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 4
Time spent in forums: 59 m 10 sec
Reputation Power: 0
|
|
PHP-General - Submit separably triggered form parts at once
Hi
I'm using PHP to create forms for user to fill up. part of the form is not for everyone, so users who want to fill it up has to click on a box below the form to trigger new fields. I'm using Ajax for triggering the hidden part of the forms. Ajax will make a new part of the form apear in the page without having to refresh.
The problem is that when I trigger several of the hidden parts I can submit them all to the data base at once. each of them was triggered at a different time and it has its own save button.
How can I save them at once.
"Proprofs" quiz making site is a good example. user can add different type of questions as he goes in making a quize the different questions for will appear on the page then will be submitted at once.
Ajax code.
function handleChange(cb) {
//get the selected value
var value = cb.value;
var divNum = cb.value;
//status variable for validation
var status;
(cb.value == 0 )?status ='new': status =2;
alert (cb.value);
//set image back to delete and undo deletion
if (cb.name =='undo')
status='delete';
if (cb.value==0)
//check if browser suports ajax
var xmlhttp = null;
if(typeof XMLHttpRequest != 'udefined'){
xmlhttp = new XMLHttpRequest();
}
else if(typeof ActiveXObject != 'undefined'){
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
else
throw new Error('You browser doesn\'t support ajax');
//open connection with activateImages.php to recieve the active images as an acho
xmlhttp.open("GET", "ManageQuestionsImages.php?status="+status + "&id="+value,true);
if (status !='new'){
//check if ready to recieve
xmlhttp.onreadystatechange = function (){
if(xmlhttp.readyState == 4)
window.activate(xmlhttp,divNum);
};
xmlhttp.send(null);
}
else {
//check if ready to recieve for add new template form
xmlhttp.onreadystatechange = function (){
if(xmlhttp.readyState == 4)
window.activated(xmlhttp);
};
xmlhttp.send(null);
}
}
//recieve the active images then insert them in the specified location of the page.
function activate(xhr,divNum){
if(xhr.status == 200){
document.getElementById(divNum).innerHTML = xhr.responseText;
}
else
throw new Error('Server has encountered an error\n'+
'Error code = '+xhr.status);
};
//recieve the active form then insert it in template div.
function activated(xhr){
if(xhr.status == 200){
document.getElementById('template').innerHTML = xhr.responseText;
}
else
throw new Error('Server has encountered an error\n'+
'Error code = '+xhr.status);
}
|