Spiga

How to send array by post method

by Gabi Solomon

Sending array by POST is easyer then you thought :)

All you need to do is name the variables a certain way :

<form METHOD="post" ACTION="index.php" METHOD="post" METHOD="post"><input TYPE="text" NAME="array[0]" />

<input TYPE="text" NAME="array[1]" />

<input TYPE="submit" NAME="submit" VALUE="Submit" /></form>

in the action file you acces the variable like this

$array=$_POST['array']

also if you don’t care about the array key’s you can even do like this

<form METHOD="post" METHOD="post" ACTION="index.php" METHOD="post" METHOD="post" METHOD="post">
<input TYPE="text" NAME="array[]" />
<input TYPE="text" NAME="array[]" />
<input TYPE="submit" NAME="submit" VALUE="Submit" />

</form>

this way they the array keys will take numeric values starting with 0

Hope this helped someone of a bit of trial and erorr and looking forword to you’re coments

Related Posts

  • George
    Very useful! Thank u :)
  • Blah
    Wait, does method = post?
  • constantmeiring
    amazing! thanks!
  • @tranquillity
    You welcome
  • Hi GABI, tnx for your example...i was in trouble with that for 2 days, but now i solved my problems :-) tnk you very very very much!
  • how do you repost it ?
  • dsf
    Let's complicate the things:
    I have a form like yours:






    and I want to request this array and repost it to other page page2.php

    In the page2.php I receive Array instead of the values of the array!
    Can you help?
  • you welcome denis
  • Been trying to figure this out for 2 days; think it boiled down to single quotes instead of double. This seems to be a very rarely documented method that I had to have for my design. Anyway, your exampled solved my issue and I wanted to thank!
blog comments powered by Disqus