PHPverse 2025

Voting

: max(six, five)?
(Example: nine)

The Note You're Voting On

akohlsmith at mixdown dot org
25 years ago
ldap_add() will only honour the $entry["attribute"][x]="value" *if there are multiple values for the attribute*. If there is only one attribute value, it *MUST* be entered as $entry["attribute"]="value" or ldap_add() sets the value for the attribute to be "Array" instead of what you put into $entry["attribute"][0].

Here is a little routine I wrote up to do this automatically. when you're parsing the input, just use multi_add():
<?php
function multi_add($attribute, $value)
{
global
$entry; // the LDAP entry you're gonna add

if(isset($entry[$attribute]))
if(
is_array($entry[$attribute]))
$entry[$attribute][count($entry[$attribute])] = $value;
else
{
$tmp = $entry[$attribute];
unset(
$entry[$attribute]);
$entry[$attribute][0] = $tmp;
$entry[$attribute][1] = $value;
}
else
$entry[$attribute] = $value;
}
?>
multi_add() checks to see if there is already a value for the attribute. if not, it adds it as $entry[$attribute]=$value. If there is already a value for the attribute, it converts the attribute to an array and adds the multiple values correctly.

How to use it:
<?php
switch($form_data_name)
{
case
'phone': multi_add("telephoneNumber", $form_data_value); break;
case
'fax': multi_add("facsimileTelephoneNumber", $form_data_value); break;
case
'email': multi_add("mail", $form_data_value); break;
...
}
?>
In the system I designed the form has pulldowns with names ctype1, ctype2, ctype3, etc. and the values are "fax, mail, phone...". The actual contact data (phone number, fax, email, etc) is contact1, contact2, contact3, etc. The user pulls down what the contact type is (phone, email) and then enters the data (number, address, etc.)

I use variable variables to fill the entry and skip blanks. Makes for a very clean form entry system. email me if you're interested in it, as I think I'm outgrowing the size of note allowed here. :-)

<< Back to user notes page

To Top