Form Submition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aspekt9
Forum Commoner
Posts: 43
Joined: Wed Dec 06, 2006 5:03 pm

Form Submition

Post 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);
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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
}
(#10850)
aspekt9
Forum Commoner
Posts: 43
Joined: Wed Dec 06, 2006 5:03 pm

Post 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'.
Post Reply