php - two submit buttons for the same form
Get the solution ↓↓↓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&campID=<?PHP echo $_GET['campID'] ?>&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>
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>
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>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function format() on string
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.
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.
About the technologies asked in this question
PHP
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
CSS
CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.
https://www.w3.org/TR/CSS/#css
HTML
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.