Page 1 of 1

Form Submition

Posted: Wed Mar 14, 2007 6:44 pm
by aspekt9
This is a bit of a mixed question. I have a line that adds a delete button to a form and I have an onClick procedure that confirms if the user wants to delete an article, how can I use PHP to code a statement so if they click OK it deletes the article from the database? Or have it link to a page like events.php?do=delete or call a function? Or do I absolutely have to use javascript? Here's my code:

Code: Select all

$delbutton = '<input type="submit" value="Delete" name="delete"%s>';
			$jsconfirm = ' onclick="return confirm(\'' . $LANG01[39] . '\');"';

sprintf ($delbutton, $jsconfirm);

Posted: Wed Mar 14, 2007 7:30 pm
by Christopher
In the PHP page that received the form submission you could do something like:

Code: Select all

if ($_POST['submit'] == 'Delete') {
     // Delete code here
} elseif ($_POST['submit'] == 'Submit')  {
     // Normal form handler code here
} else {
     // First time in, for not submitted
}

Posted: Wed Mar 14, 2007 7:56 pm
by aspekt9
That looks to be the way I was looking for except I tested it out with a quick function and added:

Code: Select all

if ($_POST['submit'] == 'Delete') {
    $msg .= "deleted";
	} elseif ($_POST['submit'] == 'Submit')  {
    $msg .= "submitted";
	} else {
	$msg .= "nothing";
	}
It seems like the onClick function may be interrupting the $_POST because no matter what it returns 'nothing'.