Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form submit to page but erase current page from history

    I want to do some processing between page 1 and page 3
    I submit via post to page 2, process then submit via post to page 3 BUT I need to erase from history page 2.
    Code:
    <FORM NAME="theForm" ACTION="JavaScript:{window.location.replace('i4swq.php')}" METHOD="post">
    <input type="text" name="find" value="7"><br>
    <input type="submit" value="Submit">
    </form>
    erase history but never posts
    Code:
    <FORM NAME="theForm" ACTION="i4swq.php" METHOD="post">
    <input type="text" name="find" value="7"><br>
    <input type="submit" value="Submit">
    </form>
    posts but does not delete page 2 from history
    Help!
    Thanks,
    Ray

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    8,083
    Thanks
    37
    Thanked 1,081 Times in 1,077 Posts
    Here is a number of things you could do.
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    
    </head>
    
    <body>
    
    <form id="theForm" action="test.php" method="post" target="_blank">
    <input type="text" name="find"><br>
    <input type="button" onclick="myFunction()" value="Submit form">
    </form>
    
    <script>
    document.getElementById("theForm").elements[0].value = 7;
    function myFunction() {
    	document.getElementById("theForm").submit();
    	var TestVar = document.getElementById("theForm").find.value;
        alert ("You typed: " + TestVar);
    	document.getElementById("theForm").elements[0].value = "";
    }
    </script>
    </body>
    </html>
    But I believe your second page is PHP and it gets the POST variable from the first page the following would work:
    PHP Code:
     <?php
    $page1_var 
    7;

    echo 
    "
    <!DOCTYPE HTML>
    <html>
    <head>

    </head>

    <body>

    <form id='theForm' action='test.php' method='post' target='_blank'>
    <input type='text' name='find'><br>
    <input type='button' onclick='myFunction()' value='Submit form'>
    </form>

    <script>
    document.getElementById('theForm').find.value = 
    $page1_var;
    function myFunction() {
        document.getElementById('theForm').submit();
        document.getElementById('theForm').elements[0].value = '';
    }
    </script>
    </body>
    </html>"
    ;
    ?>
    Last edited by sunfighter; Jun 22nd, 2017 at 02:59 AM.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  3. #3
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    3,427
    Thanks
    4
    Thanked 488 Times in 476 Posts
    My only question would be WHY?!? Seriously, screwing with the history even if you could do it (you kind of can from JavaScript) isn't something you should be doing on something as simple as a form submit.

    The only reason to consider it is to prevent resubmission, and that's what verifying a session hash is for. Generate a random has, put it in the PHP session, put another copy with the form as a hidden input. When they submit, compare the hash, if it doesn't match reject it, if it does match accept it and delete the hash from the session so it cannot be used again.

    Aka, handle it server side not client side, since anything done client-side can just be slapped aside anyways... or worse, fall apart miserably when users do things like disable JavaScript. (590 million+ NOSCRIPT plugin users between four browsers, just something to consider.)
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    http://www.cutcodedown.com

  4. #4
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    8,083
    Thanks
    37
    Thanked 1,081 Times in 1,077 Posts
    Having wwoke up and had 2 cups of coffee, I see deathshadow is right and my code is garbage. Use sessions.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


 

Tags for this Thread

Posting Permissions

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