PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 29th, 2012, 04:41 PM
yousg27 yousg27 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 yousg27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 10 sec
Reputation Power: 0
Question 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);
}

Reply With Quote
  #2  
Old December 29th, 2012, 04:54 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,880 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 11 h 31 m 43 sec
Reputation Power: 581
1) Enclose your PHP code (of which there is none) in [ PHP ] tags (see sticky at the top of this forum) and your Javascript in [ CODE ] tags. Also use proper indentation for both.
2) You only need 1 submit button if you put all the fields in a single form. You can make some of the fields hidden and then make them visible as appropriate with Javascript. There is no need to have multiple forms. You use the 'POST' method for your PHP script and use the $_POST associative array to access fields in your script (it doesn't matter to PHP if they are visible or not on the client side).
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Submit separably triggered form parts at once

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap