Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 30 September 2006 - 11:11 PM

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????



#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 30 September 2006 - 11:18 PM

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?

#3 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 30 September 2006 - 11:29 PM

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...

#4 doni49

doni49
  • Members
  • PipPipPip
  • Advanced Member
  • 515 posts
  • LocationCentral MO

Posted 30 September 2006 - 11:38 PM

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.
Don

#5 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 30 September 2006 - 11:51 PM

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:

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

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

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

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

EDIT:  doni beat me to it.  i'll leave this here just as an explanation for why the form isn't working.

#6 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 01 October 2006 - 12:33 AM

THANKs GUYS!!!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users