简体   繁体   中英

two submit buttons for the same form

Lets says that I have form and in the end I have 2 buttons

1 - send test form

2 - send live form

both send the same form. How can I send parameter to the server so I will know if its test or live?

Thanks

<form method='post' action='index.php?page=mailing&amp;campID=<?PHP echo $_GET['campID'] ?>&amp;act=<?PHP echo $actType ?>' id="Form" >     
    <table class="sort">
        <tr>
            <td>email address</td>
            <td><input type="text" name="emailTest" value="<?PHP echo $user_details['email'] ?>" /></td>
        </tr>
        <tr>
            <td></td>
            <td><a href="#" class="button3d" onClick="document.getElementById('Form').submit()">send test</a></td>
            <td><a href="#" class="button3d" onClick="document.getElementById('Form').submit()">send live</a></td>
        </tr>
    </table>
</form>

Just check in php if 'submit' field is 'test' or 'live'.

<form method='post' action='' id="Form" >     
    <table class="sort">
        <tr>
            <td>email address</td>
            <td><input type="text" name="emailTest" value="" /></td>
        </tr>
        <tr>
            <td></td>
            <td><button type="submit" name="submit" value="test">Test</button></td>
            <td><button type="submit" name="submit" value="live">Live</button></td>
        </tr>
    </table>
</form>

You'll either need to use JS, or one submit button, and a radio button. The latter is a better option, as you can't accidentally submit something to the wrong queue. Also, you should really be using a submit button, not an anchor.

The reason I would prefer the radio buttons is because once you click submit, you're past the point of no return. The radio button allows you to to click the wrong one, and then change it.

 input[type="submit"] { background: none; border: 0; color: blue; text-decoration: underline; cursor: pointer; } 
 <form method='post' action='' id="Form"> <table class="sort"> <tr> <td>email address</td> <td> <input type="text" name="emailTest" value="" /> </td> </tr> <tr> <td> <input type="radio" name="testLive" value="test" id="test" /> <label for="test">Submit as Test</label> </td> <td> <input type="radio" name="testLive" value="live" id="live" /> <label for="live">Submit as Live</label> </td> </tr> <tr> <td colspan="2"> <input type="submit" value="Submit" /> </td> </tr> </table> </form> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM