i have a form with several inputs and corresponding buttons. The input name attribute and button id are both the same. i.e
<form method="post" action="update.html">
<input type="text" name="title">
<button id="title">Submit</button>
<input type="text" name="metaKeywords">
<button id="metaKeywords">Submit</button>
<input type="text" name="metaDescription">
<button id="metaDescription">Submit</button>
</form>
now what I want to do is get the id of the button click and then insert its value inside my php function code in the following places;
<?php
function update() {
// specify target file name to update
$fileName = 'variables.php';
// Let's make sure the file exists and is writable first.
if (is_writable($fileName)) {
// load target filename contents inside a variable
$content = file_get_contents($fileName);
// use reg ex to find and replace variable contents within target filename
$content = preg_replace('/\$**INSERT_BUTTON_ID_HERE**=\"(.*?)\";/', '$**INSERT_BUTTON_ID_HERE**="'.$_POST["**INSERT_BUTTON_ID_HERE**"].'";', $content);
// open target filename for writing
$handle = fopen($fileName, 'w');
// Write $content to our opened file.
fwrite($handle, $content);
// success message
echo "<p>Success, localisation file updated.</p>";
// close opened file
fclose($handle);
} else {
echo "<p class='errorMessage'>The localisation file is not writable</p>";
}
}
if (!empty($_POST['**INSERT_BUTTON_ID_HERE**'])) {
update();
}
?>
is this possible?