Welcome to WebmasterWorld Guest from 54.145.104.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

getting array values from a form

     
11:40 am on Aug 7, 2013 (gmt 0)

5+ Year Member



Hi,

Having some trouble getting some values from input arrays.

Trying out something simple before scaling it up as I need alot more inputs than this.

<input type="text" name="option[one]"/>
<input type="text" name="option[two]"/>
<input type="text" name="option[three]"/>
<input type="text" name="option[four]"/>


Tried various bits to get any values entered into them fields to display, but nothing. Such as the following:


$yourArray = $_POST['option'];
foreach ($yourArray as $attributes){
echo key($yourArray).' '.$attributes.'<br>';
}

foreach ($_POST['option'] as $key => $value) {
echo "<p>".$key."</p>";
echo "<p>".$value."</p>";
echo "<hr />";
}



var_dump ($_POST['option']); gives me 'null'.

I basically need to grab any input field that has something entered into it. There are other fields in the form that need to be separate from this group of fields, so thinking of using input arrays for the solution. But, I cant get the simplest of things to work before checking if the input is empty and naming them correctly.
8:58 pm on Aug 7, 2013 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



seems like the form is not posting, what's the method of the form set to?

also I always prefer this way to dump post vars, then I don't mess with it

echo '<p>POST:<pre>';
print_r($_POST);
echo '</pre>';
9:56 am on Aug 8, 2013 (gmt 0)

5+ Year Member



Turned out, even though I was taking things basic on this, the form I put it in that it was going in, isn't and had a few other things going on that conflicted with the input array.

Tried it on a blank page, with just those options and echoing out the input with no data checking, and it worked fine.

Got it all sorted in the end :)
3:27 pm on Aug 8, 2013 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



glad you got it sorted :)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month