Jump to content

POST not working...form within a form???


jwwceo

Recommended Posts

I have a POST form that is very basic. I have used it many times.

It is not working. I think the problem may be that due to the structure of the HTML, I have a form within a form. Is this allowed??

I have a table within a table, and one form is in this table. The larger table has it's own form elements.

I am thinking of just removing the table within the table and replacing it with a DIV that is positioned in the same place. That way, the DIV can be anywhere in the HTML and won't be within another form.

Any other ideas to solve this????

Link to comment
Share on other sites

if your structure lands a form within a form, you've clearly mis-structured your data.  why do you have a form within a form?  it shouldn't matter what kind of container it's in, you should still not be declaring nested forms.

why is it such that there is a form within a form?
Link to comment
Share on other sites

It's kinda wierd situation...kinda hard to explain.....

I have dynamically generated delete buttons. One for each entry in my database. In order to get the delete buttons to work I need to make each within it's own form. When they are not within their own form they don't work...I'm not sure why. I think because some of the data that is being deleted is also dynamic and shares the same field name as other records. Anyway, the way this is layed out is ina  scetion of my page where there are other form fields and the flow of the HTML has these delete forms within the main form for the page.

I think I can structure it so theres no form within a form, I'll just have to use more than 1 for the main page. Just chop it in 2 with the delete forms in the middle...this should work...
Link to comment
Share on other sites

It sounds like you're saying that you have a "delete" button next to each record in the table that's displayed.  Why not just put a checkbox next to each record?  Then a Submit button at the bottom.

When the submit button is clicked, delete all records that were checked.

Display the record as a link.  Assume for a minute that you want to delete a user.  userID is unique.  So your link could look like:
deleteuser.php?user=baduser

Then deleteuser.php would retrieve the userID from the Get array. 

Personal, I'd prefer the first suggestion.  If you had multiple records to delete you could just check them all.  The second one would require you to keep clicking the links.
Link to comment
Share on other sites

the reason you can't put multiple buttons into one form is that once you hit a submit button, how does it decide what information to send?  should it send the whole form, up to only the button pressed, only the record between the last button and this button?  computers don't deal well with ambiguity.  furthermore if all the delete buttons are named the same thing, how does it decide which one was actually pressed?

there are a few ways around this:

first of all, as you said, each delete button and its related record can go into their own form.  to do this, you need to ensure that each form contains only its relevant record and its delete button.  each record must have an opening and closing form tag of its own.

another option is to make a checkbox for each record.  this way not only can the user delete as many as they want without having to constantly press a button for each, but you can nestle all of the records into one form.  simply do something like this:

[code]<input type="checkbox" name="delete[]" value="record1">
<input type="checkbox" name="delete[]" value="record2">[/code]

you will then be given an array of record values in the form:

[code]$_POST['delete'][0] => 'record1'[/code]

so you merely need to do a foreach() loop through $_POST['delete'] to get all the records the user chose to delete.

[b]EDIT:  doni beat me to it.  i'll leave this here just as an explanation for why the form isn't working.[/b]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.