note 1606 modified in function.ldap-add by irchtml
| From: | irchtml@php.net | Date: | Wed, 25 Feb 2004 06:17:10 +0000 |
| Subject: | note 1606 modified in function.ldap-add by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65694@lists.php.net to get a copy of this message | ||
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():
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:
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. :-)
--was--
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():
<pre>
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;
}
</pre>
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:
<pre>
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;
...
}
</pre>
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. :-)
http://www.php.net/manual/en/function.ldap-add.php