Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsUse one HTML form and make both controls submit that form. A normal <a href> navigates to a URL; it does not send the form fields as POST data. For a link-like appearance, use a real <button type="submit"> and style it with CSS. At the PHP endpoint, check the request method and, when necessary, a named action field.
The reliable pattern: one form, two submit controls
Browsers send form controls through a <form>. PHP then exposes URL-encoded or multipart form values in the $_POST associative array. Every value you need on the server must have a name attribute; an id by itself does not create a $_POST key.
<form method="post" action="process.php" id="taskForm">
<input type="hidden" name="action" value="run">
<input type="text" name="query">
<button type="submit" class="link-like">Run</button>
<button type="submit" class="tile-like">Run from tile</button>
</form>
Clicking either button submits the same fields to process.php with the POST method. A CSS class changes the appearance, not the control’s semantics.
Choose the PHP condition that matches what you need
Check that the request is POST
Use the request method when any POST to this endpoint should enter the handler:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$query = $_POST['query'] ?? '';
// Validate $query, then process it.
}
?>
This distinguishes a POST request from a GET request, but it does not identify which form action was chosen.
Check a deliberate action field
When several actions share an endpoint, send a named marker and test its value:
Rank #2
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST'
&& isset($_POST['action'])
&& $_POST['action'] === 'run') {
$query = $_POST['query'] ?? '';
// Validate and process the requested action.
}
?>
A hidden field is predictable regardless of which submitter initiated the request. If you instead rely on a submit button’s name, remember that JavaScript submission methods may omit the clicked button’s name/value.
Make a submit button look like an anchor
This is the preferred solution when the visible result is a form submission rather than navigation:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall.link-like {
border: 0;
padding: 0;
background: none;
color: #06c;
text-decoration: underline;
font: inherit;
cursor: pointer;
}
.link-like:focus-visible {
outline: 2px solid currentColor;
outline-offset: 3px;
}
The element remains keyboard-accessible, participates in native form validation, fires the form’s submit event, and has the expected button behavior for assistive technology.
If an existing div must trigger the form
Replace the div with a button if you can. If changing the markup is impossible, give the div button semantics, make it keyboard-focusable, and handle both keyboard activation keys:
Rank #4
<form method="post" action="process.php" id="taskForm">
<input type="hidden" name="action" value="run">
<input name="query">
</form>
<div id="runTile" role="button" tabindex="0" aria-label="Run query">
Run query
</div>
<script>
const form = document.getElementById('taskForm');
const tile = document.getElementById('runTile');
function submitFromTile() {
// requestSubmit() performs normal validation and dispatches submit.
form.requestSubmit();
}
tile.addEventListener('click', submitFromTile);
tile.addEventListener('keydown', (event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
submitFromTile();
}
});
</script>
requestSubmit() behaves like a user pressing a submit button, including constraint validation and the form’s submit event. Calling form.submit() bypasses those steps and does not provide a submitter, so a button-specific name/value may not arrive in PHP. The hidden action field avoids that dependency.
When an anchor is the right control
Use an anchor when the operation is navigation:
<a href="results.php?query=example">View results</a>
That is a GET navigation. It does not submit the current form’s controls as POST data. If the server operation changes data or otherwise requires POST, use a submit button instead. Avoid href="javascript:..."; it produces misleading navigation semantics and creates avoidable keyboard and accessibility problems.
Free tools Windows power users keep installed
One-click scans. No signup required.
Common reasons isset($_POST[...]) is false
- The clicked element is a plain anchor or a non-submitting div, so no form request was made.
- The form uses
method="get"or omits the method, so values are in the query string rather than$_POST. - The field has an
idbut noname. - JavaScript calls
form.submit()and the code expects the clicked submit button’s name/value. - The PHP condition tests the wrong action value or assumes a field that the form does not send.
- The request body is JSON. PHP does not populate ordinary
$_POSTentries from JSON; read the raw body withphp://inputand decode it instead.
A practical decision guide
| Need | Recommended control | Server-side test |
|---|---|---|
| Send form fields to PHP | <button type="submit"> |
$_SERVER['REQUEST_METHOD'] === 'POST' |
| Keep a link-like visual style | Submit button styled with CSS | Same as any form submit |
| Keep an unchangeable div | Div with button semantics plus click and keyboard handlers calling requestSubmit() |
Check a hidden named action field |
| Navigate to another URL | <a href="..."> |
Read GET parameters, not $_POST |
| Send JSON rather than form encoding | JavaScript request with a JSON body | Read and decode php://input |
Validation and security still belong on the PHP side
Client-side controls and JavaScript improve interaction, but they do not prove that a request is valid. On the server, verify the method, require the expected action value, validate every submitted field, enforce authorization, and apply CSRF protection where the application needs it. Treat all values in $_POST as untrusted input.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




