i have a form with several inputs and corresponding buttons. The input name attribute and button id are both the same. i.e
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;
is this possible?
Code:
<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>
Code:
<?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('/\$**[B]INSERT_BUTTON_ID_HERE[/B]**=\"(.*?)\";/', '$**[B]INSERT_BUTTON_ID_HERE[/B]**="'.$_POST["**[B]INSERT_BUTTON_ID_HERE[/B]**"].'";', $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['**[B]INSERT_BUTTON_ID_HERE[/B]**'])) {
update();
}
?>
Comment