Saturday, December 29, 2012

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);
}








--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: