Hey Someone
I'm writing some code to sort some lists with drag and drop, then enter your name into a text field, and it sends info to a php script which displays how many elements in each list. (link to requirements
here)
Anyway, it has to all be done a certain way, and I've done everything except I have to set a hidden form element to a certain string to send off to the php script, and Its not working. It is a requirement to do this though post, and using $_Request (am I doing that part right? I'm a little confused to what $_Request is)
The line in question is commented around, without that line it will pop up with the correct string, but with it in it wont do anything.
If anyone wants me to spoiler this for the sake of the form, I will.
The JS/Html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>CPS630 Lab 2</title>
<style type="text/css">
.hidden {
visibility:hidden;
margin-top:-20px;
}
</style>
<script type="text/javascript" src="/dojoSrc/dojo.js"></script>
<script type="text/javascript">
dojo.require("dojo.dnd.*");
dojo.require("dojo.event.*");
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.Button");
function byId(id){
return document.getElementById(id);
}
function updateVars(){
var dl = byId("clothList");
var lis2 = dl.getElementsByTagName("li");
var list2Count = lis2.length - 1;
var dl = byId("foodList");
var lis3 = dl.getElementsByTagName("li");
var list3Count = lis3.length - 1;
var countToSend = "Food:"+list2Count+";Clothes:"+list3Count;
/////////////////////////////
// document.myForm.lists.value = countToSend;
////////////////
alert(countToSend);
}
function buttonPressed()
{
updateVars();
dojo.io.bind({
url: 'getCount.php',
handler: buttonCallback,
formNode: dojo.byId('myForm')
});
}
function buttonCallback(type, data, evt)
{
if (type == 'error')
alert('Error when retrieving data from the server!');
else{
updateStatus(data);
}
}
function updateStatus(msg)
{
if(elem = document.getElementById("statusmessage"))
elem.innerHTML = msg;
}
function init(){
// list one
var dl = byId("mainList");
new dojo.dnd.HtmlDropTarget(dl, ["li11", "li12", "li2", "li3"]);
var lis = dl.getElementsByTagName("li");
for(var x=0; x<lis.length; x++){
if(x<4)
new dojo.dnd.HtmlDragSource(lis[x], "li11");
else
new dojo.dnd.HtmlDragSource(lis[x], "li12");
}
// list two
var dl = byId("clothList");
new dojo.dnd.HtmlDropTarget(dl, ["li11"]);
var lis = dl.getElementsByTagName("li");
for(var x=0; x<lis.length; x++){
new dojo.dnd.HtmlDragSource(lis[x], "li2");
}
// list three
var dl = byId("foodList");
new dojo.dnd.HtmlDropTarget(dl, ["li12"]);
var lis = dl.getElementsByTagName("li");
for(var x=0; x<lis.length; x++){
new dojo.dnd.HtmlDragSource(lis[x], "li3");
}
var sumbitButton = dojo.widget.byId('sumbitButton');
dojo.event.connect(sumbitButton, 'onClick', 'buttonPressed')
}
dojo.event.connect(dojo, "loaded", "init");
</script>
<p>Drag Items from The Main List into the coresponding lists below. Clothing Items will only be accepted by the Clothing list, and Food Items will only be accepted by the Food List.</p>
<p><b>Main List</b></p>
<ul id="mainList">
<li>Pants</li>
<li>Shirts</li>
<li>Shoes</li>
<li>Socks</li>
<li>Peanuts</li>
<li>Hamburgers</li>
<li>Candy</li>
<li>Bread</li>
</ul>
<p>List One: <b>Clothing</b></p>
<ul id="clothList">
<li class="hidden">test</li>
</ul>
<p>List Two: <b>Food</b></p>
<ul id="foodList">
<li class="hidden">test</li>
</ul>
<form id="myForm" method="post">
<input type="text" id="name" name="name" />
<input type="hidden" id="lists" name="lists" />
</form>
<button dojoType="button" id="sumbitButton">DOJO BUTTONS ARE COOL</button>
<br /><br />
<div id="statusmessage"></div>
I've also tried
<input type="hidden" id="lists" name="lists" value=countToSend />
but that doesn't work either.
the php:
<?php
/****************
// getCount.php
****************/
ereg('((([a-z]|[A-Z]|[0-9]|_)*):([0-9]*);)((([a-z]|[A-Z]|[0-9]|_)*):
([0-9]*);)', $_REQUEST['lists'], $matches);
header('Content-type: text/plain');
printf("Thanks {$_REQUEST['name']}.<br />Your Lists: $matches[2]
($matches[4]) and $matches[6] ($matches[8])<br />");
?>
This is due tonight, and I'm so damn close.
Posts
http://www.thelostworlds.net/
The php script is given to us and we cannot change it (we just hand in out html file)
I'll try printing out what the php is receiving now.
prints nothing.
prints out
test; echo $names; echo test2; echo $_REQUEST; ?>
so, I dont think it's sending anything, or/and the php and/or the html isn't working properly
any ideas?
http://www.thelostworlds.net/
a simple script like this
will just print out
$testVar;" ?>
(note the ?> at the end....)
so somethings very wrong.
edit: okay now you do. Try using echo instead of print mebbe. Also, get rid of the first semicolon in the fourth line.
Something must be wrong with my server set up.
but, the line of code
<input type="hidden" id="lists" name="lists" value=countToSend />
should work (combined with my original code up top) right?
I'm thinking I'm just going to hand this in and talk to my professor tomorrow.