-
Jan 21st, 2013, 01:31 PM
#1
Thread Starter
Lively Member
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?
-
Jan 21st, 2013, 06:09 PM
#2
Thread Starter
Lively Member
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.
-
Jan 21st, 2013, 11:10 PM
#3
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
-
Jan 22nd, 2013, 06:39 AM
#4
Thread Starter
Lively Member
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 :-(
-
Jan 22nd, 2013, 09:52 AM
#5
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
-
Jan 22nd, 2013, 10:34 AM
#6
Thread Starter
Lively Member
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!
-
Jan 22nd, 2013, 11:49 AM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|