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
?– Andrei Coelho
This way you’ll be able to catch him
$_GET
– Andrei Coelho
@Andreicoelho Good idea... just put in action rs... is that the action was empty.
– Sam
rsrs... Sometimes the simplest we do not see.
– Andrei Coelho
I actually thought I had it all wrong.
– Andrei Coelho
@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.
– Sam
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.
– Andrei Coelho
On the first page load (before submitting the form) you do not pass the ID?
– bfavaretto
@bfavaretto Yes, I get the ID that comes in the URL.
– Sam
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
@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.
– Sam
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– Isac
Uncle, see if this solves your
eval
https://ideone.com/pvX607– user60252
@Leocaracciolo Po, thanks grandpa, but I did it otherwise, just enjoy:
$prefix = "dia"; ${$prefix.$x};
– Sam
http://sandbox.onlinephpfunctions.com/code/c44feea50dd4bc0c1a5425944e6f66665b627cc6
– user60252