Question : PHP array, problems with multiple checkboxes

Hi Experts,

I'm working on an application which has multiple rows of 23 checkboxes, and some text fields as well in each row.

Each field in the row is named as such : name="contact-<?php echo $row_rsCurrent['idcode']; ?>[]"   which when submitted ends up in an array.

Each of the checkboxes define a role that the person performs in their company, and the text fields are their name, email, job title and id code.

There can be from 1 - 100 rows.

I have some code from a previous question that turns this into an array, and i get the following output as an example:

contact name=Trevor Smith
role= 209047
role= Chief Financial Officer
role= [email protected]
role= 0001;0004;0005;0006;0011;0014;0025
role= Principal Organisation Contact (0001)
role= Chief Financial Officer (0005)
role= Regional/Global Business Development (0011)
role= Training & Skills Development (0006)
role= Workplace Relations (0004)

In the example output above, the first 5 lines are name, idcode, job title, email, original roles.
The remaining lines are the updated roles which he has selected. This may be none, or maybe up to 23 items.
There may not always be the first  5 values, as someone may not have an email address or a position listed.

The code that produces this is (minus some rewriting to turn the role codes into their full names):
$data =$_POST;
$isi ="";
foreach($data as $key=>$value){
      if(is_array($value)){
            
            $isi .="contact name=".$key."\nrole= ";
            foreach($value as $_key=> $_value){
          if($_key==0){
                $isi .=$_value."\n";
          }elseif($_value == end($value)){
            $isi .="role= ".$_value."\n";      
            }else{
                  $isi .="role= ".$_value."\n";
            }            
            }
            $isi .= "\n\n";
            echo $isi;

      }else{
      //$isi .=$key = $value."<br/>";
      }      
}


Is it possible to create an array which includes the first 5 values by their type?
eg:  name => Trevor Smith
Position => Chief Financial Officer
Email => [email protected]
ect

and then have each of the roles as :
role => Principle Organisational Contact (0001)
role =>Chief Financal Officer (0005)
etc...

Is it possible to create a form field like this:
<input name="contact-<?php echo $row_rsCurrent['idcode']; ?>[idcode]">
<input type="checkbox" value="r0005" name="contact-<?php echo $row_rsCurrent['contseq']; ?>[role]" />

Then maybe i could identify each element better in the array? Or am i totally off the mark here?

In the end, i need to be able to compare the original roles (from our CRM, whic shows as preselected checkboxes in each row) with the newly selected(or unselected) roles, and highlight any differences.

I'm really stuck here, and a deadline is looming.
Hope you guys can help!

Thanks.
Brett

Answer : PHP array, problems with multiple checkboxes

You are going in the right direction with the [idcode] or [role] part of the name, now all you have to do on the post back is to check if the $_key contains one of the 5 lines that you want to test for and add then in to the string in the approprate way.
Random Solutions  
 
programming4us programming4us