Hi,
ok, quick description of the problem, I'm trying to reference the postdata from some checkboxes. Unfortunately the checkboxes are dynamically generated therefore I don't know how many there are and thus can't name them individually.
I remember reading that naming them with square brackets (as "name[]") will automatically create an array in the postdata (meaning $_POST[name] is an array) is this true?
anyway, the fact is that my checkboxes are not posting. I print_r($_POST) and it comes back with all expected posts BUT not the checkbox postdata, even if I don't name them with [].
I will post code here for reference, but it's quite long. - <?PHP
-
//$visible=array();
-
echo("<LINK REL=StyleSheet HREF=\"stylesheet.css\" TYPE=\"text/css\">");
-
-
function push(&$array, &$object){
-
$array[] =& $object;
-
}
-
function CleanA($array) {
-
while ($count < count($arr)) {
-
if ($arr[$count] == "") {
-
unset($arr[$count]);
-
}
-
$count++;
-
}
-
return $arr;
-
}
-
-
-
echo("<BODY scroll=\"auto\"><script type=\"text/javascript\">\nfunction changeText(val){\nvar txtArea = document.getElementById('desc');\ntxtArea.value = val;\n}\n</script>");
-
-
$datetoday=date("d/m/y");
-
include("dbconnect.php");
-
db_connect();
-
-
-
echo("<BR><center><FORM name=main action=$PHP_SELF?TID=$TID method=\"post\" >");
-
echo("<SELECT name=\"related\" onChange=this.form.submit()><OPTION></OPTION>\n");
-
$stkgrpqueryedit="SELECT DISTINCT id, service FROM serv_resp_service ORDER BY service ASC";
-
$stkgrpsqledit=mysql_query($stkgrpqueryedit)or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $stkgrpqueryedit");
-
-
$i=0;
-
$lenedit=mysql_numrows($stkgrpsqledit);
-
-
while ($i<$lenedit){
-
$stkgrpname=mysql_result($stkgrpsqledit,$i,"service")or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $stkgrpqueryedit");
-
$stkgrpid=mysql_result($stkgrpsqledit,$i,"id")or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $stkgrpqueryedit");
-
-
echo("<OPTION>$stkgrpname</OPTION>\n");
-
-
$i++;
-
-
};
-
echo("</SELECT>");
-
-
$hidden="$existing,$_POST[hidden]";
-
$hidden=ereg_replace(" ","_",$hidden);
-
$visible=explode(",",$hidden);
-
$_POST[related]=ereg_replace(" ","_",$_POST[related]);
-
push($visible,$_POST[related]);
-
if(isset($_POST[remove])){
-
unset($visible[$_POST[remove]]);
-
-
}
-
$run=count($visible);
-
$m=0;
-
echo("<BR><TABLE>");
-
while ($m<$run){
-
-
-
// $visquery="SELECT name from stk_groups WHERE id=$visible[$m]";
-
// $visrun=mysql_query($visquery);
-
// $visresult=mysql_result($visrun,0)or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $visquery");
-
if($visible[$m]!=""){
-
echo("\n<TR><TD class=darker align=left>$visible[$m]</TD><TD class=darker align=centre><a href=\"#\" ><img src=\"http://tmc-tectest/fileadmin/open_resources/image_library/icons/icon_delete.gif\" border=0 alt=\"$m\" onmousedown=\"changeText(this.alt)\" onmouseup=main.submit()></a></TD><TD class=darker align=right><input type=\"checkbox\" value=\"$visible[$m]\" name=\"deleted[]\"></input></TD></TR>");
-
}$m++;
-
}
-
if($m=$run){
-
echo("</TABLE>");
-
}
-
-
foreach($visible as $key => $value) {
-
if($value == "") {
-
unset($visible[$key]);
-
}
-
}
-
$visible = array_values($visible);
-
if($op=="upload"){
-
// insertSQLhere
-
}
-
$visible=implode(",",$visible);
-
ereg_replace ( ",,", " ", $visible );
-
ereg_replace ( "_", " ", $visible );
-
ereg_replace ( "<a href=\"#\" ><img src=\"http://tmc-tectest/fileadmin/open_resources/image_library/icons/icon_delete.gif\" border=0 alt=\"$m\" onmousedown=\"changeText(this.alt)\" onmouseup=main.submit()></a>\n<BR>", " ", $visible );
-
echo("<INPUT type=hidden name=\"hidden\" value=$visible></input>");
-
echo("<input type=hidden id=\"desc\" name=\"remove\">");
-
echo("</FORM>");
-
echo("<FORM name=go action=\"$PHP_SELF?op=update&TID=$TID\" method=\"post\">");
-
echo("<INPUT type=hidden name=\"upload\" value=$visible></input>");
-
echo("<input type=submit value=Save onclick='this.form.submit();window.close()'>");
-
echo("<p class=tdborder style=\"width:300px\" align=center>to remove a erroneous selection from the list, click the trash icon.<br> to remove an entry from the database entirely, check the box and select \"save\"</p>");
-
-
if($op=="update"){
-
-
$upload=explode(",",$_POST[upload]);
-
$i=0;
-
$run=count($upload);
-
While($i<$run){
-
$IDSQL="SELECT DISTINCT `id` FROM serv_resp_service WHERE `service` LIKE \"$upload[$i]\"";
-
$IDQUERY=mysql_query($IDSQL) OR DIE (mysql_error().$IDSQL);
-
$ID=mysql_result($IDQUERY,0) OR DIE (mysql_error().$IDSQL);
-
$MID=$MID.",".$ID;
-
$i++;
-
-
} $MID=substr($MID, 1);
-
$MID=explode(",",$MID);
-
$MID=array_unique($MID);
-
-
$i=0;
-
$MID=array_unique($MID);
-
$run=Count($MID);
-
-
while ($i<$run){
-
-
$sql1="SELECT * FROM serv_resp_related WHERE (`source`=$TID AND `linked`=$MID[$i]) OR (`source`=$MID[$i] AND `linked`=$TID)";
-
$query1=mysql_query($sql1);
-
@$result1=mysql_num_rows($query1);
-
if ($result1=0){
-
$sql="INSERT INTO serv_resp_related (`source`,`linked`) VALUES ($TID,$MID[$i])";
-
print_r("$_POST[deleted]");
-
// $query=mysql_query($sql) OR DIE(mysql_error());
-
};
-
$i++;
-
-
}
-
-
$del=$_POST["deleted"];
-
-
print_r($_POST);
-
-
foreach ($del as $key => $value)
-
{
-
$sql="DELETE FROM serv_resp_related WHERE (`Source`=$value AND `Linked`=$TID) OR (`Source`=$TID AND `Linked`=$value";
-
echo("$sql<BR>");
-
}
-
}
-
-
-
-
-
-
-
-
?>
5 3875 Atli 5,058
Recognized Expert Expert
Hi.
Yes this is true. If you create <input> elements named 'name[]', PHP will threat all of them as an array.
Keep in mind tho, boxes that are not checked will not be included in the post.
For example. -
<?php
-
// Print the FORM
-
$numberOfBoxes = 10;
-
echo '<form action="?" method="POST">';
-
for($i = 0; $i < $numberOfBoxes; $i++) {
-
echo '<br /><input type="checkbox" name="box[]" value="box'. $i .'" /> Box '. $i;
-
}
-
echo '<br /><br /><input type="submit" name="boxSubmit" />';
-
echo '</form>';
-
-
// Check if the data has been posted an print it
-
if(isset($_POST['boxSubmit'])) {
-
echo "<pre>";
-
echo "\n<b>Boxes checked:</b>";
-
foreach($_POST['box'] as $boxName) {
-
echo "\n - $boxName";
-
}
-
echo "</pre>";
-
}
-
?>
-
Will print out all the boxes you checked. The rest will not be a part of the array.
Hi.
Yes this is true. If you create <input> elements named 'name[]', PHP will threat all of them as an array.
Keep in mind tho, boxes that are not checked will not be included in the post.
For example. -
<?php
-
// Print the FORM
-
$numberOfBoxes = 10;
-
echo '<form action="?" method="POST">';
-
for($i = 0; $i < $numberOfBoxes; $i++) {
-
echo '<br /><input type="checkbox" name="box[]" value="box'. $i .'" /> Box '. $i;
-
}
-
echo '<br /><br /><input type="submit" name="boxSubmit" />';
-
echo '</form>';
-
-
// Check if the data has been posted an print it
-
if(isset($_POST['boxSubmit'])) {
-
echo "<pre>";
-
echo "\n<b>Boxes checked:</b>";
-
foreach($_POST['box'] as $boxName) {
-
echo "\n - $boxName";
-
}
-
echo "</pre>";
-
}
-
?>
-
Will print out all the boxes you checked. The rest will not be a part of the array.
Thanks for confirming that, in that case i'm even more confused. if that is the case the code I am using should definately work, but for some reason the post for the checkboxes is never set...
Atli 5,058
Recognized Expert Expert
I see you have two <form> elements. Are you sure you are submitting the right one?
pbmods 5,821
Recognized Expert Expert
Heya, Tarantulus.
Have you tried submitting the form with the checkboxes checked? Checkboxes do not show up in form results at all unless they are checked.
Doh!
thanks Atli,
I noticed that the checkboxes were in the wrong form element.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: sammmista |
last post by:
hello experts,
Plz dont treat this as another newbie query , i did my homework but
still getting nowhere :( :( :(
Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD).Unable to
post data from html form to php file(connecting to mysql database and
inserting into a table) .
This seemingly simple problem is making me go mad !!! I googled
extensively and already tried the following
|
by: ginette |
last post by:
I really need help with a strange problem.
i have a page having ONLY this cleaned and washed HTML code, no client
scripting at all and "some" folks are unable to post any file till
"some" are able. All using IE6 (SP1 or not)
Leaving the <input type="file"> unassigned is ok for everyone but when
you select a file, even a SMALL SMALL SMALL 10 bytes almost empty txt
file, the form fails to be submitted.
|
by: Froefel |
last post by:
This is the second time in a few weeks that I write posts that never
show up in the group.
Is there something wrong with this group? Does anyone have similar
experiences?
What are you all using to read and write posts in news groups? I use
Google Groups but I'm getting suspicious of its quality...
-- Hans
|
by: adrive |
last post by:
guys,
I can't seem to find any info on how to pass a list of checked checkboxes through POST method of ajax.
Unlike traditional forms, when you submit a button, a list of selected checkboxes with the same name will allow you to retrieve it at the server side (php in my case).
IS this the only way?
param = "selecteditem = " + document.myform.item.value;
param+ = "&selecteditem = " + document.myform.item.value;
|
by: runway27 |
last post by:
i am using a self submitting form
<form action="<?php echo $_SERVER; ?>" method="POST" id="test2" name="test1">
i need to do a validation of textfields, checkboxes, radio buttons
i am able to read, display and validate textfields after the form has been submitted however i am getting an error for
checkbox and radio buttons.
| |
by: souporpower |
last post by:
Hello All
I am trying to activate a link using Jquery. Here is my code;
<html>
<head>
<script type="text/javascript" src="../../resources/js/
jquery-1.2.6.js"</script>
<script language="javascript" type="text/javascript">
|
by: mamul |
last post by:
Hi All,
Could you please someone help me. Thanks in advance.
Actually my application is building fine. when i tries to run this from visual studion run option, it showing me error . But this is working from the exe file in the release folder. when i am running the exe file of the application it is working fine. I want to run from VIsual studio. Plz help me someone.
There are two database are used in my application. With one database it...
|
by: sandeepsangshetty |
last post by:
Hi Friends,
I'm unable find check box control in my webpage.
When building the page I'm getting "checkbox null" and "false".
Can any help me to find the solution.
I'm pasting the code here.
-------------------------------------------------------------------------------
_BigCart.ascx
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |