post without form ?

This is a discussion on post without form ? within the PHP Language forums, part of the PHP Programming Forums category; I have this list of logs stored in a MySQL DB. I display them in a list and next to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-16-2005
Angelos
 
Posts: n/a
Default post without form ?

I have this list of logs stored in a MySQL DB.
I display them in a list and next to each log I have a del view LINK

I want to add Checkboxes next to each log and keep del and view links as
well.

Then you can select all the logs you want to delete, hit a delete Link and
send the variables in a script...
Can you do that without having a form ?

Can you have a checkbox without having a form ?

It sounds a bit awkward but I am just wandering

<li><a href="transaction.php?contCat=<? echo $contCat
?>&action=delete&contSubCat=<? echo $contSubCat ?>&content_id=<?php echo
$row['backup_id']; ?>"onClick="return formConfirm('del')">Del</a><input
name="<?php echo $row['backup_id']; ?>" type="checkbox" value="1">
</li>


Reply With Quote
  #2 (permalink)  
Old 06-16-2005
ZeldorBlat
 
Posts: n/a
Default Re: post without form ?

Nope -- without a <form> tag the checkbox values won't make it to the
next page.

Reply With Quote
  #3 (permalink)  
Old 06-16-2005
Tony
 
Posts: n/a
Default Re: post without form ?

"Angelos" <angelos@redcatmedia.net> wrote in message
news:d8s537$ros$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
>I have this list of logs stored in a MySQL DB.
> I display them in a list and next to each log I have a del view LINK
>
> I want to add Checkboxes next to each log and keep del and view links as
> well.
>
> Then you can select all the logs you want to delete, hit a delete Link and
> send the variables in a script...
> Can you do that without having a form ?
>
> Can you have a checkbox without having a form ?


Not one that will do anything, unless you also want to use JavaScript. Of
course, that brings on a whole pile of other issues.

Why would you not want to have a form?



Reply With Quote
  #4 (permalink)  
Old 06-16-2005
Kenneth Downs
 
Posts: n/a
Default Re: post without form ?

Angelos wrote:

> I have this list of logs stored in a MySQL DB.
> I display them in a list and next to each log I have a del view LINK
>
> I want to add Checkboxes next to each log and keep del and view links as
> well.
>
> Then you can select all the logs you want to delete, hit a delete Link and
> send the variables in a script...
> Can you do that without having a form ?
>
> Can you have a checkbox without having a form ?
>
> It sounds a bit awkward but I am just wandering
>
> <li><a href="transaction.php?contCat=<? echo $contCat
> ?>&action=delete&contSubCat=<? echo $contSubCat ?>&content_id=<?php echo
> $row['backup_id']; ?>"onClick="return formConfirm('del')">Del</a><input
> name="<?php echo $row['backup_id']; ?>" type="checkbox" value="1">
> </li>


If you want to use javascript you can do this. In place of a submit button
you have a button that runs a script in the browser. The script walks
through the checkboxes and builds a list of the ones that are checked. It
generates a link that might look like this:

var Destination = "deletes.php?list=" + list;

Then it jumps to that location with:

window.navigate(Destination);


--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Reply With Quote
  #5 (permalink)  
Old 06-16-2005
Angelos
 
Posts: n/a
Default How Can You get the checkbox Values

> <li><a href="transaction.php?contCat=<? echo $contCat
> ?>&action=delete&contSubCat=<? echo $contSubCat ?>&content_id=<?php echo
> $row['backup_id']; ?>"onClick="return formConfirm('del')">Del</a><input
> name="<?php echo $row['backup_id']; ?>" type="checkbox" value="1">
> </li>


Ok considering wi have the above code tha loops and lists a Number of DB
entries
how can we assign a checkbox in each of them and then retrieve each
checkboxs' value in order to delete the appropriate record when the form is
submited ?

THanks !!!



Reply With Quote
  #6 (permalink)  
Old 06-16-2005
eilks
 
Posts: n/a
Default Re: How Can You get the checkbox Values

Ok try something like this (example code... i tried to comment in it as
much as possible):

for this example.. logs table structure:
id (primary, auto-increment)
description

---------------------

<?

include("db.php");
//connect to db

if(!isset($_POST['submit'])) {
//form isn't submitted

echo "<b>Logs</b><br><br>";

echo "<form action=\"\" method=\"post\">";


$query = "SELECT * FROM logs";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
$id = $row['id'];
$description = $row['description'];
echo "Log: $description <input type=\"checkbox\" name=\"log_$id\"
value=\"1\"><br>";
}
//get all log values, and present checkbox
//NOTE: checkbox values are prefixed with 'log_', explained later..

echo "<input type=\"submit\" name=\"submit\" value=\"Delete\">";
//input button

} else {

foreach ($_POST as $key => $value) {
if(strstr($key, 'log_')){
//if the value contains log_ then its used
if($value == '1'){
$id = str_replace("log_", "", $key);
//log_ prefix is removed to get the id
$query = "DELETE FROM logs WHERE id='$id'";
mysql_query($query) or
die (mysql_error());
//deleted..
}

}

}

echo "<b>Done</b>";

}

?>

---------------------

ok basics behind the script...

since theres an unknown number of form values the following is used:

foreach ($_POST as $key => $value) {
//code
}

....which loops through all the form elements and their values.
However this can cause a problems, because other form elements will be
picked up other than the checkboxes, such as the input button. THIS is
the reason that i prefixed all checkboxs with 'log_', so it can later
be checked.

i hope this is the kind of thing you are after ;)

-eilks

Angelos wrote:
> > <li><a href="transaction.php?contCat=<? echo $contCat
> > ?>&action=delete&contSubCat=<? echo $contSubCat ?>&content_id=<?php echo
> > $row['backup_id']; ?>"onClick="return formConfirm('del')">Del</a><input
> > name="<?php echo $row['backup_id']; ?>" type="checkbox" value="1">
> > </li>

>
> Ok considering wi have the above code tha loops and lists a Number of DB
> entries
> how can we assign a checkbox in each of them and then retrieve each
> checkboxs' value in order to delete the appropriate record when the form is
> submited ?
>
> THanks !!!


Reply With Quote
  #7 (permalink)  
Old 06-17-2005
Angelos
 
Posts: n/a
Default Re: How Can You get the checkbox Values

> i hope this is the kind of thing you are after ;)
>
> -eilks

Yep ... it looks to be what I want ;-)
That _log prefix does the work !!! :)
Thanks a lot !


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:39 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0