I only have a basic understanding of html. What i want to do is have a group of form submit buttons within the same form but i need each button to pass on two values unique to it's self (one is hidden). If i use a <input type="hidden"
Attaching second value to a form submit button.
Collapse
X
-
Yes, you can have multiple submit buttons on a single form, however if you have a hidden field within the form, each submit button is going to submit that field. If each button needs to pass a certain variable, you can assign the value of the variable to the button instead of a hidden field, that way each button will submit a different value. I once did something like this just for fun, where I used submit buttons as a menu to navigate a site. The code I used had the buttons with different values of each button would determine what content to load. You will probably want to keep each value the same and give each button a different name. Then using php, you can check which button was clicked.Originally posted by bugboyI only have a basic understanding of html. What i want to do is have a group of form submit buttons within the same form but i need each button to pass on two values unique to it's self (one is hidden). If i use a <input type="hidden"
Form would be something like
[CODE=html]
<form method="post" action="index.p hp">
<input name="val1" type="submit" value="submit" />
<input name="val2" type="submit" value="submit" />
<input name="val3" type="submit" value="submit" />
<input name="val4" type="submit" value="submit" />
</form>
[/CODE]
and then using php to determine the button that was clicked would be something like...
[CODE=php]
if($_POST['val1']) {
///code for val1
}
[/CODE]
Good luck and hope this helps! -
Thanks! Yes this is what i would like to do but each of the submit buttons needs to pass on two values. I suppose i could glue the two values into a string then explode them on the new page.
I don't think the below code is valid but it represents the idea i'm looking for...
[HTML]
<form method="post" action="index.p hp">
<input name="name" type="submit" value1="$val1" value2="$val2"/>
<input name="name" type="submit" value1="$val3" value2="$val4"/>
</form>[/HTML]
The only reason they need to be in the same form is for looks, this the only way i can figure out to get buttons to sit side by side without creating multiple <td>'s to hold each. I want them side by side and in the same <td> so that they wrap and build up multiple rows of buttons on the screen instead of one column. Maybe i can get around this by abandoning tables and using CSS?
more:
The buttons are created in a 'while' loop so the number will vary. I need to keep them with the same name so that i don't have redundant php code which has to look for the max number of possible buttons every time... hmmm unless i put that in a loop which would count up through buttons until it found the one that was submitted... it would just be so much easier if there was a way to submit two values for each button in the form....Comment
-
The buttons within the same <td> should display in a row. The code I gave you displays them in a row in IE and Firefox. Using CSS on top of that you can make the buttons look and behave in many different ways. The next thing is that the button will say what is in the value field. If this is ok, then you could assign the different values and probably be ok with it, but both values would have to be under one 'value' tag. You can't have two value tags in the same button. If this doesn't work, then you might have to assign each button a different name. Maybe a combination of different 'name' and 'value' attributes will get you what you need, or like you mentioned, use the explode() function to get each value you need. I am not sure on the look and exactly what your doing, but with a combination of these ideas, it sounds like you can get it.
As far as your second loop idea is concerned, if you go that route I would look into a switch statement within php. This might be helpful in writing one loop that will handle the form correctly depending on which button is pushed.
Good Luck!Comment
-
No Problem. Glad I was able to be of some help. :DOriginally posted by bugboyThanks for your help lumpy! I think i'll use a string and explode it on the other end.. it seems to be the most flexible and has the least redundancy.
BugBoy
Post back if you have any other questions.Comment
Comment