/    Sign up×
Community /Pin to ProfileBookmark

Posting (generic?) arrays, retrieving

Hey all. I currently have a situation here:
I let users ‘import’ certain things they can select. Now, it’s a simple foreach() loop, with ten times this in it:
<input type=”hidden” name=”custom_1[]” value=”‘.$custom_1.'” />
<input type=”hidden” name=”custom_b[]” value=”‘.$custom_b.'” />

How do I ‘link’ the two together, so I can properly have them both in my process.php?

Process.php is just this right now:

[code=php]<?php
$custom1 = $_POST[‘custom_1’];
$customb = $_POST[‘custom_b’];

foreach($custom1 as $c1)
{ echo $c1 . ‘<br />’; }
[/code]

Now, customb is supposed to be linked to that. How would I go about doing this?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@coldfire421Apr 14.2011 — Ok I made a code for you that automate the autopostback in controls. I make a textbox rather than hidden form field for you to test it

[code=php]
<html>
<head>
<title>PHP Autopost Back Control</title>
</head>
<body>
<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
$str='';
for($i=0; $i<3; $i++)
$str .= "<input type='text' name='custom[]' value='". getValue($i) ."' /><br />";

echo $str;

function getValue($i)
{
$postVal = isset($_REQUEST['custom'][$i]) ? $_REQUEST['custom'][$i] : '';
return $postVal;
}
?>
<input type="submit" value="POST" />
</form>
</body>
</html>

[/code]
Copy linkTweet thisAlerts:
@MaveauthorApr 14.2011 — I'm not really sure how that would work.

Let me try and make this clear again ;p. I have a foreach() loop, that loops an average of 10 times. In that loop, there are between 2 and 6 values each loop that need to be processed accordingly to a new page. It's possible that 1 is empty, 2 is empty, and 3 is filled, and 1 filled, 2, 3, 4 and 5 empty, and 6 filled.

So I need to process all of these values. I need to make sure that in the first possiblity, they're all marked as let's say 'a'. So, 1a is empty, 2a empty, 3a filled, 4a filled, 5a empty, and 6a empty.

Second would be marked 'b' (well, marking is not neccesarily, but I need to seperate them.)

Any one have any idea? :<
Copy linkTweet thisAlerts:
@coldfire421Apr 15.2011 — yea that is what my code is suppose to do. i juz make it 3 loop but you can make it 10 or even more
Copy linkTweet thisAlerts:
@coldfire421Apr 15.2011 — Ok for you to understand I add something to my code try to test it
[code=php]
<html>
<head>
<title>PHP Autopost Back Control</title>
</head>
<body>
<?php
$maxControlCount=10;
$ctrVal='';

for($i=0; $i<$maxControlCount; $i++)
{
$ctrVal .= "The value of control $i is <b>".getValue($i).'</b><br />';
}
echo $ctrVal;
?>
<p />
<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
$str='';
for($i=0; $i<$maxControlCount; $i++)
$str .= "<input type='text' name='custom[]' value='". getValue($i) ."' /><br />";

echo $str;

function getValue($i)
{
$postVal = isset($_REQUEST['custom'][$i]) ? $_REQUEST['custom'][$i] : '';
return $postVal;
}
?>
<input type="submit" value="POST" />
</form>
</body>
</html>
[/code]
×

Success!

Help @Mave 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...