Forum Moderators: open

Message Too Old, No Replies

Multiple Form Submit/Action with Javascript?

multiple form submit with javascript

         

xKillswitchx

3:20 pm on Aug 6, 2007 (gmt 0)

10+ Year Member



Hello all,
I am stuck with a problem. I am designing a small web app (in php) that fetches data from a mysql database, which is printed in rows on a table. Each row has a checkbox.

What I am trying to do, is turn this into a form. You can check one or many boxes, to either edit, delete, publish or unpublish those item(s). I have the functions to remove items, etc and can do all the PHP things, but I dont know javascript. Basically, I have a couple images that are the submition, and depeding on which you click, it will send you and the $_POST data where you need to go (for example, click edit sends you to index.php?task=content&action=edit/delete/publish).

Is there any quick way to tag the input type=submit to have this sent there and will it be able to handle the multiple checkboxes?

Thanks.
I would link to a demo, but its only running localhost at the moment. I do plan to release GNU in the future, or just as a free framework to let a community take over.

rocknbil

2:27 am on Aug 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard xKillswitchx, something like this?

<input type="checkbox" name="prod_1" id="prod_1" value="1"> <label for="prod_1">Edit 1</label>
<input type="checkbox" name="prod_2" id="prod_2" value="2"> <label for="prod_2">Edit 2</label>
<input type="checkbox" name="prod_3" id="prod_3" value="3"> <label for="prod_3">Edit 3</label>
<input type="checkbox" name="prod_4" id="prod_4" value="4"> <label for="prod_4">Edit 4</label>
<input type="checkbox" name="prod_5" id="prod_5" value="5"> <label for="prod_5">Edit 5</label>

You should be able to do that with one form, except that it could potentially make for a very long page when you arrive. A check box value exists in the post only if it's checked, so you only need to see if it is in the post - that is,

if (isset($_POST["prod_1"])

Of course, you'd want to do a loop to check that. If I select items 1, 3, and 5 in the above, you'd iterate through the post variables, take the ones that start with prod_, and set a form based on their values:

<label for="prod_5">Content 5</label>
<textarea name="prod_5" id="prod_5" rows="5" cols="55"> (value for content 5)</textarea>

As I said this can make for a rather long form, but is this what you are looking for?

I would link to a demo,

Be sure you read the TOS and sticky post at the forum head, no links allowed. :-(

xKillswitchx

4:33 am on Aug 16, 2007 (gmt 0)

10+ Year Member



Sorry for such a late response, we have construction going on here and lost internet for a while.

Anyways, that is sort of what I need. I know how to loop everything through and checking with isset...

What I am trying to do exactly, is in my table, next to each data, I want to be able to check any boxes and click the image below for delete or unpublish, o rpublish, and so on (except editing, dont want to mass edit).

I cant figure out how to change each action for submitting the form. I want unpublishing to send to task=content&action=unpublish and say deleting to send to task=content&action=delete.

Is there a way to change each action of these images (the images are submit type)?