1

Here is the snapshoot of my form. The input values under LPO (1st column) are hidden, I just showed them here to show complete form.

enter image description here

if color_id (first left most inputbox) is 37 its DB value is BB552 as displayed. And if its 3, the value of that color is BB110, but when its 0, it means a user has selected Custom and written a value by him self in the third row it is FFBBBAA.

I need to submit the form to PHP

The field names are as follows

color_id[] <-- Hidden input
order_id[] <-- Hidden input
subcolor_id[] <-- Select
subcolor_string[] <-- Input
material_id[] <-- Select
weight[] <-- input

When I post the form, in PHP

<?PHP

$count = count($_POST['weight']);

for($i = 0; $i < $count; $i++){
    $color_id = $_POST['color_id'][$i];
    $order_id = $_POST['order_id'][$i];
    $material_id = $_POST['material_id'][$i];
    $weight = $_POST['weight'][$i];

    // i can count one post item and can iterate over all.

    if($color_id == 0){
       $color_id = $_POST['subcolor_id'][$i]; // this give me wrong result;
    }
    
}

So when 0 is there, admin approving this form, can leave it to custom or change the color back to some value from DB

I want to know what are the possibilities for getting the proper sub color values if first hidden input color_id has 0.

So far the one which I thought of is to add two more hidden fields in Sub Color columns to match their index, but this will require me to completely re-write the del sub color code

Is there any other way which can save me from doing lots of alterations to this form?

4
  • Do sub-categories have a specific number of items in them? Commented Feb 26, 2013 at 6:19
  • You mean to ask Sub Colors dropdown items? Yes they are coming from database, and every time color_id is 0, the dropdown is displayed. Commented Feb 26, 2013 at 6:22
  • I just want to ask, won't you get the sub color values in subcolor_string[] ? Commented Feb 26, 2013 at 6:23
  • Yes i can do that, but I need to update all the JS and forms, which I dont want to Commented Feb 26, 2013 at 6:27

2 Answers 2

3

as eds mentioned it totally makes sense.. u shud do this way

$j=0;
$count = count($_POST['weight']);

for($i = 0; $i < $count; $i++){
$color_id = $_POST['color_id'][$i];
$order_id = $_POST['order_id'][$i];
$material_id = $_POST['material_id'][$i];
$weight = $_POST['weight'][$i];

// i can count one post item and can iterate over all.

if($color_id == 0){
   $color_id = $_POST['subcolor_id'][$j]; // this give me wrong result;
   $j++;
}

}

this shud solve your problem..

Sign up to request clarification or add additional context in comments.

Comments

2

Your other option is to declare another iterator $j outside of the loop, starting at 0, and manually incrementing that iterator after you read a subcolor each time. Then it should always be the index of the next subcolor_id you need to read.

1 Comment

Hmm it sounds interesting, let me try. I will let you know

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.