...

View Full Version : Variable's posting problem



MarioPro
09-05-2005, 03:39 PM
I can't get the values from Keywords selected to my query after hitting the Save button. I've tried lots of different approaches and can't find where the problem is :o

Thanks in advance for any help on this issue.

Here's the page code where after submitting the form the script should display the KEYWORDS entered to the left select list.


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for(i=0; i<tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length
for(i=0; i<fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if(fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
} else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c=0; c<arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c=0; c<arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
}

function selectAll(box) {
for(var i=0; i<box.length; i++) {
box[i].selected = true;
}
}
</script>
</head>
<body>
<p>
<?
if($save=Save){
echo $keywords;
}
?>
</p>
<form method="post" action="photoedit.php?save=Save" name="editphoto" enctype="multipart/form-data">
<table border="0" cellpadding="2" cellspacing="1" id="sqlcontainer" name="sqlcontainer">
<tr>
<td align="center" bgcolor="#dbe7f9">photo_title_en</td>
<td align="center" bgcolor="#dbe7f9" nowrap="nowrap"> varchar(255) </td>
<td bgcolor="#dbe7f9"><input type="text" name="photo_title_en" value="" size="40" maxlength="255">
</td>
<td bgcolor="#dbe7f9">&nbsp; </td>
<td bgcolor="#dbe7f9">&nbsp; </td>
</tr>
<tr>
<td align="center" bgcolor="#e6f0ff">photo_keywords</td>
<td align="center" bgcolor="#e6f0ff" nowrap="nowrap">text</td>
<td align="right" bgcolor="#e6f0ff"><select multiple size="10" name="keywords[]" id="keywords" style="width:150" onDblClick="move(this.form.keywords,this.form.keyword_pad)">
</select>
</td>
<td bgcolor="#e6f0ff"><input type="button" onClick="move(this.form.keywords,this.form.keyword_pad)" value=">>" id=button1 name=button1>
<input type="button" onClick="move(this.form.keyword_pad,this.form.keywords)" value="<<" id=button2 name=button2>
</td>
<td bgcolor="#e6f0ff"><select name="keyword_pad" id="keyword_pad" size="10" multiple="multiple" onDblClick="move(this.form.keyword_pad,this.form.keywords)">
<option value="Couple, ">Couple</option>
<option value="Child, ">Child</option>
<option value="Man, ">Man</option>
<option value="Two, ">Two</option>
<option value="Female, ">Female</option>
<option value="Young, ">Young</option>
</select>
</td>
</tr>
</table>
<br >
<input name="submit" type="submit" tabindex="119" value="Save">
</form>
</body>
</script>
</html>

NancyJ
09-05-2005, 04:08 PM
as far as I can tell, you're passing $keywords as an array but you're trying to output it as a variable.
try

foreach($keywords as $keyword){
echo $keyword;
}

MarioPro
09-05-2005, 04:16 PM
Hi Nancy,

Even though it still doesn't work. The Keywords aren't getting up there after submit. :(

NancyJ
09-05-2005, 04:37 PM
have you set $keywords anywhere? eg. $keywords = $_POST['keywords'] ... or $_POST['keywords[]'] cant remember the exact syntax.

MarioPro
09-05-2005, 04:42 PM
Hi,

Yes, $keywords[] is set in the form (red)

<form method="post" action="photoedit.php?save=Save" name="editphoto" enctype="multipart/form-data">
<table border="0" cellpadding="2" cellspacing="1" id="sqlcontainer" name="sqlcontainer">
<tr>
<td align="center" bgcolor="#dbe7f9">photo_title_en</td>
<td align="center" bgcolor="#dbe7f9" nowrap="nowrap"> varchar(255) </td>
<td bgcolor="#dbe7f9"><input type="text" name="photo_title_en" value="" size="40" maxlength="255">
</td>
<td bgcolor="#dbe7f9">&nbsp; </td>
<td bgcolor="#dbe7f9">&nbsp; </td>
</tr>
<tr>
<td align="center" bgcolor="#e6f0ff">photo_keywords</td>
<td align="center" bgcolor="#e6f0ff" nowrap="nowrap">text</td>
<td align="right" bgcolor="#e6f0ff"><select multiple size="10" name="keywords[]" id="keywords" style="width:150" onDblClick="move(this.form.keywords,this.form.keyword_pad)">
</select>
</td>
<td bgcolor="#e6f0ff"><input type="button" onClick="move(this.form.keywords,this.form.keyword_pad)" value=">>" id=button1 name=button1>
<input type="button" onClick="move(this.form.keyword_pad,this.form.keywords)" value="<<" id=button2 name=button2>
</td>
<td bgcolor="#e6f0ff"><select name="keyword_pad" id="keyword_pad" size="10" multiple="multiple" onDblClick="move(this.form.keyword_pad,this.form.keywords)">
<option value="Couple, ">Couple</option>
<option value="Child, ">Child</option>
<option value="Man, ">Man</option>
<option value="Two, ">Two</option>
<option value="Female, ">Female</option>
<option value="Young, ">Young</option>
</select>
</td>
</tr>
</table>
<br >
<input name="submit" type="submit" tabindex="119" value="Save">
</form>

NancyJ
09-05-2005, 04:53 PM
the form field keywords[] != $keywords

MarioPro
09-05-2005, 05:15 PM
Hi Nancy,

Yes, but even if I change it to $keywords the variable isn't posted, seems like the form field keywords doesn't exist. I think that this has something to do with the Javascript and not the PHP of HTML. :( :(

NancyJ
09-05-2005, 05:31 PM
print_r($_POST);
should show what is in post

NancyJ
09-05-2005, 05:42 PM
doh! ofcourse... ;)
Had to actually compile see this in action to realise what the problem is, your keywords arent being posted because they're not selected ;)
add a little javascript into your on_submit that selects everything in keywords.



<form .... onsumbit="selectAllOptions(this.keywords)">



function selectAllOptions(obj){

for(var i=0;i<obj.options.length;i++)
{
obj.options[i].selected = true;
}
return true;
}

MarioPro
09-05-2005, 05:44 PM
Nancy,

As you may have noticed, I have two select lists: the left one is for the "keywords" that I want to be saved, and the right one is the "keyword_pad" that is populated from the database.

What's happening now after your print_r post? Well, I noticed that the only variables passed to the script will come from the "keyword_pad" select IF and ONLY those which are in fact selected.

Now, the problem is how to get the left select to pass the variables into the the $_POST. Humm... it seems this is more Javascript. :rolleyes:

NancyJ
09-05-2005, 05:48 PM
in select boxes only the selected items are passed through with the form data.

...I'm guessing you havent seen my previous post ;)

MarioPro
09-05-2005, 05:58 PM
;) Right. Now I have the variable out there thanks to you Nancy :thumbsup:

Now I'll try to find a way to "auto-select" the items on the left select box, like an onChange...

Thnks again for your valuable help! :thumbsup:

NancyJ
09-05-2005, 06:01 PM
<form .... onsumbit="selectAllOptions(this.keywords)">



function selectAllOptions(obj){

for(var i=0;i<obj.options.length;i++)
{
obj.options[i].selected = true;
}
return true;
}

should select all options in keywords onsubmit



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum