Jump to content

[SOLVED] Dynamic number of forms, trying to determine which form button was clicked


Recommended Posts

Hi,

 

I've been toying with this a bit. I have a list, generated from database output, of names paired with emails. Along with each name/email tuple I want to have a button which should POST the name + email pairs such that I can deal with them when the page reloads.

 

Simple enough. The problem I'm running into is the fact that I don't know how many rows of data I will have. Therefore I can't just statically name any of the form items. I've tried, as the data is being outputted from the query, keeping track of what row I'm on and simply appending this to the name + id of the submit form items. However, this doesn't seem to be allowed as the button is not recognized as having been clicked once the page reloads.

 

How can I get around this? I know this is probably a simplistic issue and I've tried searching, but all that I can find on dynamic forms is not applicable.

 

Thanks!

Hi,

 

Is the reason you need to know which button was clicked so you know which row in the database the submitted tuple refers too?

 

Robin

 

Yes, this is correct. The button is to delete the row from the database.

Hi,

 

For form containing a tuple, also generate a hidden form field inside the given form containing the primary key (id) for that row in the database. E.g.:

 

<input type="hidden" name="row_id" value="$rowId" />

 

Then the submitted row_id value is the id you want to use in the where  clause of your delete statement.

 

Robin

Actually, that didn't quite do it. I'm still having the same issue: I can't put something generated dynamically into the value of an input. ie if I just put

 

value="$rowId"

 

the value will be exactly that, $rowId. If this had worked, it should work just the same to call them name1, name2, name3, etc. And this doesn't work either:

 

value="<?php $rowId ?>"

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.