0

Got a form that has the option to add many inputs for ordering pictures via picture number.

In theory a customer could order 1 picture or 100, how would I go about the PHP.

As coding up to 100 $_POST[] for each possible field seems crazy as each of the added fields as it's own unique NAME attr using jQuery.

Anyone got any bright ideas?

2
  • 1
    What do you have so far? And I'm not 100% clear on what you're requesting. Commented May 5, 2011 at 15:43
  • Well I've got the possibility of having upto 100 form fields all with unique NAME attr. So I need to POST the information from the form. Commented May 5, 2011 at 15:51

3 Answers 3

4

Using field names that end in square brackets will cause PHP to create the entries as an array:

<input name="foo[]" value="foo" />
<input name="foo[]" value="bar" />
<input name="foo[]" value="moo" />
<input name="foo[]" value="cow" />

will produce the following: $_REQUEST['foo'] (or $_POST['foo']/$_GET['foo']) is an array like this:

array(
    0 => 'foo',
    1 => 'bar',
    2 => 'moo',
    3 => 'cow'
);
Sign up to request clarification or add additional context in comments.

Comments

1

You could try something like

for ($i=0;$i<100;$i++){
    if (isset($_POST['picture'.$i])){
        // Do something
    } else {
        break;
    }
}

Comments

0

You can do something like this

<input type="checkbox" value="picnumber" name="pictures[]" />

<?php
$pics = $_POST['pictures']; // here you will get an array of values of the selected images
?>

1 Comment

Unfortunataly I've got a text input for the picture name, and a select box for each picture with picture sizes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.