View Full Version : Resolved Posting Without a Form

07-03-2010, 03:23 AM
<fieldset class="submit">
<?php if ($site_exist >= 1){
echo "<input type=\"submit\" name=\"submit\" value=\"Update\">";
} else { echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">";
} ?>
<!-- The next line is the part in question -->
<input type="button" name="delete" value="Delete"
onClick="return confirmSubmit()">
<script type="text/javascript"><!--
function confirmSubmit(){
var agree=confirm("Are you want to delete this site from our index?");
if (agree) return true ;
else return false ; } // -->

Both the submit and the delete button are inside of a form. The submit button submits the form. The delete button is almost the same as the submit button, except instead of the form data I want it to post a separate, single variable (named delete or siteDelete and its value being true). I don't want to use javascript, the js code is only their to add a confirmation button.

07-03-2010, 05:52 AM
Shouldn't this be in the PHP forum?

07-03-2010, 06:16 AM
No. There is PHP in my code, but my question is HTML related (PHP is required for retrieving data, my question is only about submitting data).

07-03-2010, 08:31 AM

You can have as many as submit button inside a form but all the buttons will be submitted to the form action file only.

There you can get the name of the button using isset($_POST['buttonname']) clicked and you can differentiate the functions that has to be done for the particular submitted or clicked button.


07-03-2010, 09:28 AM
I don't want the delete button to submit the form, that's why I'm using type="button" instead of type="submit". What I want is for the button to post delete['true'] or delete="true" but only after javascript confirmation returns true. I was thinking something like

<input type="button" name="delete" value="Delete"
onClick="return confirmSubmit()" action="user.php?select=3">
but I'm not sure how that would work, since value on buttons is used to determine their text rather than the value of their name and if the confirmation would work since it's inside the same tags as the action. If there is any way to have the button submit a form that it isn't contained in, that will work too- there's probably a hundred ways to make this work, I only need one way, be it with HTML, PHP, or javascript.

07-03-2010, 08:15 PM
I think the input is submitted as a variable with its value too. i.e. here:

<form action="http://example.com/" action="get">
<input id="update" name="update" value="Update" type="submit"/>
<input id="delete" name="delete" value="Delete" type="submit"/>

Pressing the "delete" button would pass the variable "delete" with the value "Delete" to your processing script.

07-03-2010, 11:25 PM
So if I change it to
<input id="delete" name="delete" value="Delete" type="button"
onClick="return confirmSubmit()" action="user.php?section=3" method="post"/>
would that work?

And change
$delete = $_POST['delete']
$delete = $_POST['delete']

07-03-2010, 11:31 PM
Only way to know is to try.

07-04-2010, 12:47 AM
Nope. Is the onClick event considered active scripting? If all else fails I guess I'll have to use javascript, but I'd prefer for users to be able to delete their information without requiring it to be enabled.

07-04-2010, 12:55 AM
Wow, I guess for some reason it never occurred to me that submitting the form wouldn't be a problem, since it's just going to be deleted anyway. Problem Solved=D.