How to make multiple submit buttons toggle with PHP
My newbie question of the day is....
I have a comment function on my site that I have 3 versions of for the same page. I have one that has specific traits for A. signed in and looking at own profile B. signed in looking at someone elses profile C. Not signed in at all
I have it working ju开发者_开发问答st great depending on what criteria the user falls under. I have a submit button that sends one of these formats, so my question is, how do I toggle (in this case two,because C. does not require a button) two different buttons for the same if(isset chunk?
Here is what I am wanting to add onto/alter:
if(isset($_POST['commentProfileSubmit']) && $auth) {
Not sure if this is what you need, but:
in the html markup, use something like
<input type="submit" name="commentProfileSubmit" value="<?= $pageVersion ?>" />
, $pageVersion stand for the variable/value you use to determine your page version.
Then in php, you have
if (isset($_POST['commentProfileSubmit'])) {
switch ($_POST['commentProfileSubmit']) {
case 'A':
echo 'from A';
break;
case 'B':
echo 'from B';
break;
}
Do you mean you have two (or more) submit buttons for the same form? Give each button unique name:
<input type="submit" value="Button A" name="button_a" />
<input type="submit" value="Button B" name="button_b" />
And in php check the POST value:
if(isset($_POST['button_a'])){
echo 'Button A clicked';
}else if(isset($_POST['button_b'])){
echo 'Button B clicked';
}
If I understood your question correctly...
精彩评论