0

So im asking what options do I have other than redirecting GET variables when Im trying to repopulate a form?

Im thinking I can create session variable and use that also. Am I correct that these are the ONLY 2 ways?

What I have now is:

if ( count($m) > 0 ) {    
// there is an error in fields filled out so we are sending user back to     form.
$_SESSION["myarray"] = $m;
header("location: ./edit.php?datefield=".$datefield."&text=".$entry."&flag=".$flag);    
}

but this reveals my variable to the user. I want to avoid this.

UPDATE I re-worded my question and the code to be clearer. I also like found that the solution for me was to use an include('edit-error.php'). Which is basically the original edit.php with everything stripped out but the code needed to generate the form, and I populated edit-error.php with the needed variables. I never had this in my tool box before so I am grateful to the user who suggested it.

4
  • 2
    so many ways. but why redirect when you could simply include the view and pre-populate the data in it? Commented Apr 7, 2015 at 2:17
  • @pala_4 I am not understanding what you mean by "simply include the view and pre-populate". Seems I HAVE to redirect BACK to page with form in order to do this right? Is there an example of this method you speak of? Commented Apr 7, 2015 at 7:12
  • 1
    you can include('edit.php'), and inside edit.php, you can look for variables that you have set to specify that there are errors, and also pre-fill form values with those already entered. instead of redirecting Commented Apr 7, 2015 at 7:16
  • Ahhh! I see what you mean now. This does give me some ideas. Let me play with it. Thanks. Commented Apr 7, 2015 at 11:33

2 Answers 2

1

One way that you can consider for hide information (not totally, but more stronger than GET) of user is create a JSON with your infos and send a POST request to your page.

Personally, I still preferring sessions, but there are other ways.

Sign up to request clarification or add additional context in comments.

Comments

0

The solution I used was provided my user pala_ , so thanks pala_ I up voted your comment.

I used include('edit-error.php'). Which is basically the original edit.php with everything stripped out but the code needed to generate the form, and I populated edit-error.php's form with the needed variables. I never had this in my tool box before so I am grateful to the pala_ who suggested it.

This allows me to conduct server side validation and redisplay the form again with user input, so they can resubmit. I was using header(Location) with paramaters to submit as GET and I didnt want that. Using include() is a perfect solution for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.