How to make php wait for an confirm box to finish

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
raphael75
New php-forum User
New php-forum User
Posts: 32
Joined: Fri Apr 06, 2012 9:54 pm

Mon Mar 31, 2014 10:48 am

One approach would be to have 2 files like this:

confirm.html
contains the javascript asking if the user wants to reset.

Code: Select all

<script>
function check_reset()
{
  if(confirm('are you sure you want to reset?'))
  {
    window.location = 'reset.php'
  }
  else
  {
    window.location = 'index.php'
  }
}
</script>
Then reset.php would be like this:

Code: Select all

<?php
shell_exec('rm /tmp/*.x10');
shell_exec('/usr/bin/br --port=/dev/ttyUSB0 e all_off');
header('Location: index.php'); //redirect user back to homepage after resetting
?>



seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Wed Apr 02, 2014 1:30 am

Yes, along the same lines as the previous suggestion, have your second file do the work in the backend, and pass execution to it via ajax, so you don't even have to reload the page, and you can output results etc on the users screen. It's a better look and does exactly what you want. Personally I like using jquery for ajax, as demonstrated here: http://www.w3schools.com/jquery/jquery_ ... t_post.asp. It only takes a couple of minutes to get it going and make sense of it the first time, then you'll want to use it for everything.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests