Click to See Complete Forum and Search --> : [RESOLVED] onclick confirm


SoulAssassin
06-07-2007, 07:50 AM
I am trying a method you guys referred me to earlier, and I thought I had it but something doesn't work properly.
I have a form button that I would like to have a confirmation pop up before submit like this:

<input name="delivered_id" type="hidden" value="id21" />
<input type="button" name="deliverconf" value="Deliver" onclick="temp = window.confirm('Confirm Delivery?');">

The confirm message with Ok and Cancel buttons pops up successfully, but is suppose to set the "temp" variable to "true" or "false" once clicked, right?
But when trying this, nothing happens:

<?
if(isset($_POST['deliverconf']))
{
$delivered_id = $_POST['delivered_id'];
echo "$delivered_id";
echo "$temp";
}
?>

The "if(isset($_POST['deliverconf']))" doesn't seem to happen after I selected Ok or Cancel.
I also tried "if(isset($_POST['temp']))", but nothing.
Why can that be?

Even this does nothing:

<?
if ($temp)
{
echo "$temp";
}
?>

Any suggestions, or a better method to get a confirmation message

cahva
06-07-2007, 08:24 AM
This is purely a javascript issue. You have to return something. If it returns false the form is not submitted. If its true then the form is submitted.

This should do it:

<input type="button" name="deliverconf" value="Deliver" onclick="return confirm('Confirm Delivery?');">


Now when you click cancel it will be false and form is not submitted.

SoulAssassin
06-07-2007, 09:09 AM
I have tried this,

<input type="button" name="deliverconf" value="Deliver" onclick="return confirm('Confirm Delivery?');">

but when I click Ok, nothing happens:

<?
if(isset($_POST['deliverconf']))
{
echo "Form Sumitted";
}
?>

This doesn't make sense to me, what am I missing?

SoulAssassin
06-07-2007, 10:34 AM
Should I not maybe put the something in the <form>?

<form action="" method="post" onSubmit="return confirm('Confirm Delivery?');">

shu
06-07-2007, 11:52 AM
Of course it doesn't do anything, when the user clicks on either button of the popup window, that's the end of it. You need to tell it to submit the form:


<input type="button" name="deliverconf" value="Deliver" onclick="javascript: if (confirm('Confirm Delivery?')) this.form.submit();">

cahva
06-07-2007, 02:14 PM
Actually you dont need that if :) Example:

<?php
if (!empty($_POST)) {
print_r($_POST);
}
?>
<form action="" method="post">
<input type="hidden" name="test" value="yep">
<input type="submit" name="submit" onclick="return confirm('Sure?');">
</form>


Form wont submit if you press cancel and it will submit if you press ok.

EDIT:
Oh.. The button was type="button". Then you actually need that if :D My bad.

shu
06-07-2007, 02:32 PM
Actually you dont need that if :) Example:


Form wont submit if you press cancel and it will submit if you press ok.

EDIT:
Oh.. The button was type="button". Then you actually need that if :D My bad.

Have you tested it? With the type being submit, I think the form will get submitted regardless of whether the user presses cancel or ok on the popup window!

cahva
06-07-2007, 02:59 PM
Have you tested it? With the type being submit, I think the form will get submitted regardless of whether the user presses cancel or ok on the popup window!

Actually yes, I have tested it :)

SoulAssassin
06-11-2007, 07:02 AM
Nice one guys, the button type was my problem.
Resolved.