SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript in PHP

    Hi, I have a form and I want to display a pop-up before submitting the data.Problem is I cant call confirmation box at onsubmit or onclick event, as pop-up will appear only if no validation errors are there.

    Something like this:
    Code:
    <?PHP if(empty($err_array)){ ?>
    			<script> 
    			var ans = window.confirm('Are you sure you want to submit this form?');
    					if(ans == true){ </script>
    							<?PHP dbInsert($tbl,$insert_array);
                                echo "<div class='alert alert-success'>
                                <button class='close' data-dismiss='alert' type='button'>&times;</button>
                                Data Inserted
                                </div>";
                                unset($_POST); ?>
    					<script>   } </script>
    <?PHP } ?>
    I am trying to do this since long.Is there any solution to display confirmation window like this?
    It's easy once you know how...

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by anita_86 View Post
    Hi, I have a form and I want to display a pop-up before submitting the data.Problem is I cant call confirmation box at onsubmit or onclick event, as pop-up will appear only if no validation errors are there.

    Something like this:
    Code:
    <?PHP if(empty($err_array)){ ?>
    			<script> 
    			var ans = window.confirm('Are you sure you want to submit this form?');
    					if(ans == true){ </script>
    							<?PHP dbInsert($tbl,$insert_array);
                                echo "<div class='alert alert-success'>
                                <button class='close' data-dismiss='alert' type='button'></button>
                                Data Inserted
                                </div>";
                                unset($_POST); ?>
    					<script>   } </script>
    <?PHP } ?>
    I am trying to do this since long.Is there any solution to display confirmation window like this?
    THis sounds like you would want to use ajax to submit the form data to the php script, have the script check the data for any issues, and then output a response indicating whether the data is good or bad. The web page can then wait for that response, and if it's good the page can do the confirm, before submitting that form data back php script.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •