0

I have a scenario where I need to send some POST parameters but with the same name how can I do it? I have a similar scenario with a GET as well in which I could simply construct the URL by appending the same parameter name but how can I do it with POST. If it was for GET it would be something like

          $url=$url."&team=".$name1;
          $url=$url."&team=".$name2;

But how can I do the same with POST? Any help is appreciated I tried searching for it but couldn't find an appropriate answer

thanks in advance

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

2 Answers2

1

You Can Use hidden fields inside form data to send an Value as POST like

<input type="hidden" name="name" value="value">

In Case you don't want any user activity You can use Javascript to submit form:

<form action="http://example.com/foo" name="hiddenform" method="POST">
    <input type="hidden" name="name1" value="value1">
    <input type="hidden" name="name2" value="value2">
</form>
<script type="text/javascript">
    setTimeout("document.forms['hiddenform'].submit();",0);
</script>

Above Will Display Nothing on Screen and submit form as soon as this loads.

Side-Note: if you want to delay change value of 0 according to your needs in setTimeout("document.forms['hiddenform'].submit();",0);

Shub
  • 2,686
  • 17
  • 26
  • I had mentioned there are no user activity happening nor it has any form elements – Gotham's Reckoning Nov 17 '14 at 22:02
  • 1
    Updated My Answer Hopefully It Will Help. – Shub Nov 17 '14 at 22:09
  • Subhanker Thanks for that. I had tried that for some other scenario.I was actually wondering whether I could do it without the use of form. Apparently I got the answer from the comments from @Uby as It could be passed in as an array. thanks anyways :) – Gotham's Reckoning Nov 17 '14 at 22:24
  • 1
    Just keep in mind that user can edit the form if he wants to. – Tomáš Zato Dec 03 '14 at 01:18
  • @TomášZato indeed, but most of the users wont even notice any form submit as it happens as soon as the page loads but ofcource someone with an geeky mind can manipulate the data and OP or whoever uses this must be concerned of. – Shub Dec 03 '14 at 19:22
0

If you need the values passed through a browser address bar, you need to form the link this way:

$url = "team=".$name1.",".$name2;

Then in the main PHP code you may explode it into array chunks:

$urlArray = explode(",", $url);
Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
  • U r talking about GET and what I was asking was POST – Gotham's Reckoning Nov 17 '14 at 22:04
  • @Gotham'sReckoning POST is using the same data encoding normally. It only changes when you're sending files. Here is [an answer explaining POST format](http://stackoverflow.com/a/14551320/607407). Both PHP and Javascript have functions that allow you to generate the requests. – Tomáš Zato Dec 03 '14 at 01:20