/    Sign up×
Community /Pin to ProfileBookmark

post array using curl for values with same name?

Hi,

In the following:

[code=php]<form action=’test2.jsp’ method=’post’ ENCTYPE=’multipart/form-data’><table border=0>
<tr>
<td><input type=”checkbox” name=”showOption” value=1 checked></td>
<td>&nbsp; Origin(s) </td>
</tr>
<tr>
<td><input type=”checkbox” name=”showOption” value=2 checked></td>
<td>&nbsp; pro(s) </td>
</tr>
<tr>
<td><input type=”checkbox” name=”showOption” value=3 checked></td>
<td>&nbsp; ter(s) </td>
</tr>
<tr>
<td><input type=”checkbox” name=”showOption” value=4 checked></td>
<td>&nbsp; Sel(s) </td>
</tr>
</table></form>[/code]

Some items have the same name. Posting directly to a jsp page works as the jsp page uses multi.getParameterValues.
I would like to use curl to post to the jsp page. The jsp page only takes arrays. However, one cannot place in an array different values for a same item. Can you help me undertand how I could overcome this problem and post an array or a jsp string that could be undertood by the jsp page ?

for info, the following does not work :

[code=php]curl_setopt($ch, CURLOPT_POSTFIELDS, array(“showOption”=>”1”, “showOption”=>”2”, “showOption”=>”3”, “showOption”=>”4”)); [/code]

nor

[code=php]curl_setopt($ch, CURLOPT_POSTFIELDS, array (array(“showOption”=>”1”, “2”, “3”, “4”))); [/code]

Many thanks in advance for any help !!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindMar 08.2009 — change name="showOption" to name="showOption[B][][/B]"

the [] transforms the checkbox item into an array.

$_POST without []:
<i>
</i>Array
(
[showOption] =&gt; 4
)



$_POST with []:
<i>
</i>Array
(
[showOption] =&gt; Array
(
[0] =&gt; 1
[1] =&gt; 2
[2] =&gt; 3
[3] =&gt; 4
)

)
Copy linkTweet thisAlerts:
@patimagesauthorMar 08.2009 — thanks for the reply but I cannot change it for complexity reason (jsp script)... Any other idea ?
Copy linkTweet thisAlerts:
@OctoberWindMar 09.2009 — Then I'm afraid you're going to have a hard time getting PHP to recognize this as an array, unless you give each checkbox a unique name or assign the [B][][/B] array keyphrase.

Otherwise, you're just going to overwrite the previous $_POST[showOptions] with the latest one.
Copy linkTweet thisAlerts:
@patimagesauthorMar 09.2009 — Indeed, sounds impossible... I cannot add the [] array symbols or it is not recognized by the jsp script (it uses multi.getParameterValues if this helps)... Never thought I would say that but it looks impossible to do... Thanks anyway !!
×

Success!

Help @patimages spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...