I'm trying to get a confirmation dialog to appear when a form is submitted, but I've actually been having quite a lot of difficulty in getting it to work.

Here's what should happen:

1) The user clicks the "purge logs" submit button
2) A confirmation dialog appears
3) If the user clicks the "yes" button, the form is submitted. If the user clicks the "no" button or "close" button, nothing happens.

Here's what actually happens:
The forms submits itself without waiting for the user to click yes or no in the dialog that appears.

Here's the code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript">



            var confirm = ConfirmDialog('Confirm', 'Are you sure?');


        function ConfirmDialog(title,message){
            var confirmdialog = $('<div></div>').appendTo('body')
                modal: true, title: title, zIndex: 10000, autoOpen: false,
                width: 'auto', resizable: false,
                buttons: {
                    Yes: function(){
                        return true;
                    No: function(){
                        return false;
                close: function(event, ui){
                    return false;

            return confirmdialog.dialog("open");

<form id="form_purge" name="form_purge" method="post" action="test.php">
<button type="submit" name="submit_purge" id="submit_purge">Purge&nbsp;Logs</button>