I have a form with two different submit buttons. One is to delete the corresponding row in the MySQL, which is done on the same page, the other is to save the row to another database, which is done on a separate page. The delete action works fine, but I cannot figure out how to send the save form data to the other page without putting it in the "action" value. I've tried JavaScript, but haven't had much luck. It's a bit of a lengthy post, but I figure the more information I give, the easier it will be for a solution to be found.
Here's just the save submit button:
echo "<td><input type=\"submit\" name=\"save\" value=\"Save\" onclick=\"this.form.action='publishmod.php'\"></td>";
Here's the form code (main page):
echo "<form name=\"editmod\" method=\"post\">";
echo "<tr class='modlist'>";
echo "<td>".$row['id']."</td>";
echo "<td><div class=\"edit\" id=\"div_1\">".$row['title']."</div></td>";
echo "<td><div class=\"edit\" id=\"div_2\"><a href=".$row['mod_url'].">".$row['mod_url']."</a></div></td>";
echo "<td><div class=\"edit\" id=\"div_3\">".$row['developer']."</div></td>";
echo "<td><div class=\"edit\" id=\"div_4\">".$row['type']."</div></td>";
echo "<td><div class=\"edit\" id=\"div_5\">".$v162."$nbsp".$v164."$nbsp".$v172."</div></td>";
echo "<td><div class=\"edit\" id=\"div_6\">".$row['title'].",$nbsp".$row['developer']."</div></td>";
echo "<td><input type=\"submit\" name=\"save\" value=\"Save\" onclick=\"this.form.action='publishmod.php'\"></td>";
echo "<td><input type=\"submit\" name=\"delete\" value=\"Delete\"></td>";
echo "</tr>";
echo '<input type="hidden" name="id" value="', htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="id" value="', htmlspecialchars($row['mod_url'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="id" value="', htmlspecialchars($row['developer'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="id" value="', htmlspecialchars($row['type'], ENT_QUOTES, 'UTF-8'), '" />';
echo '<input type="hidden" name="id" value="', htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'), '" />';
echo "</form>";
}
Publish code (page that the save action is supposed to redirect to):
Variable sanitation omitted for Stack Overflow purposes.
$name = $_GET['title'];
$desc = "Installation tutorial for '.$name.'";
$url = ereg("^[A-Za-z_\-]+$", $name) + ".php";
$keywords = "'.$name.', '.$dev.'";
$type = $_GET['type'];
$link = $_GET['mod_url'];
$dev = $_GET['developer'];
$id = $_GET['id'];
// Query
$savequery = "INSERT INTO search (title, description, url, keywords, type, mod_url, developer, v162, v164, v172)
VALUES ('$name', '$desc', '$url', '$keywords', '$type', '$link', '$dev', '$v162', '$v164', '$v172')";
// Mod file creation
$file = ereg("^[A-Za-z_\-]+$", $name) + ".php";
$handle = fopen($file, 'w');
$data = '<?php
$title = "'. $name. '";
$keywords = "'. $name. ','. $developer. '";
$description = "How to install '. $name. ' for PC and Mac.";
include("templates/modheader.php");
include("templates/modfooter.php");
?>';
$save = $dbsave->query($savequery) or die(mysqli_error($dbsave));
// Run creation
echo $save;
fwrite($handle, $data);
print " mod file created!";
fclose($handle);
?>