Dev
Dev

Reputation: 1746

Go Back A Few Pages After Form Submission

Desired flow

  1. link 1 : www.example.com (list of all persons)
  2. press view button on person 1
  3. link 2 : www.example.com?view-person=1 (view details of person 1)
  4. press edit button
  5. link 3: www.example.com?edit-person=1 (editing form for person1)
  6. press submit then return to ?view-person=1

Form action in ?edit-person is action="www.example.com".

Inside www.example.com is the following snippet

if(isset($_POST['edit-person']))
{
// record edit
header("location:javascript://history.go(-1)"); // supposed to go back to ?view-person but just returns to ?edit-person
}

I've tried

header("location:javascript://history.go(-1)");

And

header("location:javascript://history.go(-2)");

But it just sends me back to ?edit-person=1 instead of ?view-person=1.

I can't also just do header("location:www.example.com?view-person='$id'"); because it sends me to www.example.com?view-person=%272%27

I dont know if what I'm planning is possible or not.

Upvotes: 0

Views: 166

Answers (2)

Aashu Spk
Aashu Spk

Reputation: 111

You're using GET Method and validating by POST, use $_REQUEST instead.

i've tried this code and it works fine.

<?php
if(isset($_REQUEST['edit-person']))
{
  echo "<script>history.go(-2);</script>";
}
?>

Upvotes: 1

Eric
Eric

Reputation: 97565

Do javascript: urls even work in the Location header? You're not doing PHP string interpolation correctly - you want:

header("location:www.example.com?view-person=$id");

Upvotes: 0

Related Questions