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

  • http://www.bitemyaxe.com Dennis

    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!

  • http://www.gsdesign.ro Gabi Solomon

    you welcome denis

  • 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?

  • http://www.gsdesign.ro Gabi Solomon

    how do you repost it ?

  • http://www.muccacomputer.com tranquillity

    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!

  • http://www.gsdesign.ro/ Gabi Solomon

    @tranquillity
    You welcome

  • constantmeiring

    amazing! thanks!

  • Blah

    Wait, does method = post?

  • Subhrojit86

    Thank you so much. This is the easiest way to do this and I've been searching for a long time. Thanks again

  • George

    Very useful! Thank u :)

  • Ccsdc

    thank you

  • Manducks

    it is not useful , when I use a checkbox which returns an array, it does not work …

    pc to phone dialer