Save Prompt for PHP form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silversubey
    New Member
    • May 2007
    • 22

    Save Prompt for PHP form?

    I have a php based checklist that stores the answers to MSSQL. Currently it has a save button at the bottom of the page that no one uses. When they exit the page without pressing save no data is recorded. Is it possible to have a prompt that would ask to save, when they try to leave? Any is help is appreciated. thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    This is not something you can do with PHP. I suspect this is possible by using JavaScript.
    I'm going to move this question over to the JavaScript forum where I'm sure the JavaScript experts will be able to give you an answer.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      You could try using onbeforeunload. It doesn't work in all browsers because it is not (yet?) part of the standards.

      An optimization might be to check that they haven't already pressed the save button before displaying the prompt.

      Comment

      • silversubey
        New Member
        • May 2007
        • 22

        #4
        Thanks for the info. I am now able to warn them at least. Has anyone seen it where the save function can be in the prompt?

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by silversubey
          Thanks for the info. I am now able to warn them at least. Has anyone seen it where the save function can be in the prompt?
          Could you elaborate? Can you post your code?

          Comment

          • silversubey
            New Member
            • May 2007
            • 22

            #6
            my form has a simple submit button to save the data


            <input type="submit" value="Save">

            by using onbeforeunload I get the prompt "You are leaving the page....Are you sure you want to navigate away". "OK" or "Cancel"

            Is it possible to have it say "you are leaving the page....do you wish to save this page before leaving." and when they click on 'OK" it saves the page before leaving.

            Here is the javascript:

            <script language="JavaS cript">
            window.onbefore unload = confirmExit;
            function confirmExit()
            {
            return "If you have made any changes without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
            }
            </script>

            Comment

            Working...