How to pick up a value via GET and others via POST at the same time?

Asked

Viewed 159 times

0

I have a link that passes a value via GET to a page:

pagina.php?id=1

Within pagina.php i have a form that will make a POST for itself, but I take the value of the id with $_GET['id'] and the form with $_POST upon submission.

The problem is that when submitting the form I also need the value of id together, but as he is received via GET, include a input hidden with name="id" on the form would not work because the id would not be received via GET.

How could I get around this by sending the id together with the form where only the id would have to be received via GET?

  • I don’t understand sam.. Because in the form action you don’t include pagina.php?id=1?

  • This way you’ll be able to catch him $_GET

  • @Andreicoelho Good idea... just put in action rs... is that the action was empty.

  • rsrs... Sometimes the simplest we do not see.

  • I actually thought I had it all wrong.

  • 1

    @Andreicoelho I’m still new in PHP, sometimes I get a little lost. Before I used to work with ASP and in it I get the value in one way, either by GET or POST.

  • Interesting... I’ve never dealt with Asp.. In php you can also pick it up in a way only through $_REQUEST. But it’s not very advisable.

  • On the first page load (before submitting the form) you do not pass the ID?

  • @bfavaretto Yes, I get the ID that comes in the URL.

  • So why can’t you put this ID in an Hidden input? I didn’t get that part. Passing the action works (at least in PHP), but seems a little awkward.

  • @bfavaretto It is that your put in the Hidden input the $_GET will not catch. But put in action no problem, it is an internal page of entries.

  • Won’t take it why? Just do <form .... method="post"><input type="hidden" name="id" value="<?=$_GET['id']?"> So it gets everything by the post. The point is that your http request only has one type, so it’s only get or post, although you can get values by $_GET on a request of the type post

  • Uncle, see if this solves your eval https://ideone.com/pvX607

  • @Leocaracciolo Po, thanks grandpa, but I did it otherwise, just enjoy: $prefix = "dia"; ${$prefix.$x};

  • http://sandbox.onlinephpfunctions.com/code/c44feea50dd4bc0c1a5425944e6f66665b627cc6

Show 10 more comments

1 answer

3


You can try it like this:

<form action="minhaacao.php?id=<?php echo $_GET['id']?>" method="post">
    <!-- demais inputs -->
</form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.