php - two submit buttons for the same form

643

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 >
    <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="#" onClick="document.getElementById('Form').submit()">send test</a></td>
      <td><a href="#" onClick="document.getElementById('Form').submit()">send live</a></td>
    </tr>
  </table>
</form>
254

Answer

Solution:

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>
519

Answer

Solution:

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>
Write your answer




Share solution ↓

Additional Information:

Link To Source
People are also looking for solutions of the problem: call to a member function getclientoriginalname() on null

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.


Similar questions

Find the answer in similar questions on our website.

17 ubuntu - How to install php extension using pecl for specific php version, when several php versions installed in system?
463 PHP form resubmitting
945 automatically php form submit using javascript
634 Create form HTML for my PHP ADODB
990 php - How To Extract Information Using The Amazon API
469 php - Wrong form is validated in symfony
122 php - Formulas not calculated when exporting as csv
109 jquery - Email contact form without PHP
251 php - Getting error Cannot modify header information
81 php - How to make all input fields (with 100+ input fields existed already) in single form as "required"?

People are also looking for solutions to the problem: Form Input name with square brackets not an array in PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.