Row Select, not quite working...
I am trying to submit a value, based on a button click, here is the php code for the button:
echo "<input type='submit' width='100%' id='bonddescription' name='bonddescription[]' value='" .$row['description']. "'><input type='hidden' id='issueid' name='issueid[]' value='".$row['issue_id']."'>";
This renders correctly, however when trying to obtain the submitted value it does not function as expected.
var_dump($_POST[$bonddescription]); shows the value from the correct row
var_dump($_POST[$issueid]); shows the full array, rather than the specific value from the selected row
I need to display the bond description on the button and would prefer to keep the issue_id field hidden if possible, so how can I stop the entire array being submited and just post the single row value, as it does for the description?
Re: Row Select, not quite working...
I can do this with checkboxes, but I can not find a single example of people doing this without checkboxes, which is odd as this scenario must come up all the time.
Re: Row Select, not quite working...
have you looked at the resulting HTML after the code has run, to make sure that it's correct? Because I don't think it's right...
Here's what I suspect... you have a form tag... and then inside the form tag, you have a bunch of these rows. The reason that the correct bonddescription comes out is because it's a submit button... so THAT value gets submitted... along WITH EVERYTHING ELSE in the form... including ALL of your hidden fields.... and since they all have the same name... they get put into an array.
So... having said that... the solution is to put EACH row into their OWN form tag... so that when it's submitted, ONLY those values are posted.
-tg
Re: Row Select, not quite working...
So you mean like this:
echo "<form>";
echo "<input type='submit' width='100%' id='bonddescription' name='bonddescription[]' value='" .$row['description']. "'><input type='hidden' id='issueid' name='issueid[]' value='".$row['issue_id']."'>";
echo "</form>";
If I do that, click submit, then the print_r($_POST) simply reads: Array()
So, something still isn't right :-(
Re: Row Select, not quite working...
Not surprised... you didn't tell it to post the form... or where to post it to....
Documentations
You need to supply the Acton which is the URL to send the data to, and the Method, which is the manner in which the data is sent, it is either Get or Post. Get will send the data through the URL ala QueryString... while the post... well sends it through the headers as post data. By default when forms aren't specified, it 1) sends it via GET to the 2) same URL that sent it (in other words it sends it right back to the same page.)
-tg
Re: Row Select, not quite working...
Oooops!
Yeah, sorry, should have spotted that.
I've learnt something new today, I never realised you could have multiple forms on a single html page!
That will help me out quite a lot, many thanks!
Re: Row Select, not quite working...
Yeah... having multiple forms on a single html page isn't always obvious... most examples have one form, one page... I went through the same realization doing the same kind of thing back when....
-tg