RE: [Phplib-users] oohForm text element with multiple attribute
Brought to you by:
nhruby,
richardarcher
|
From: Andres B. Z. <aba...@ei...> - 2003-08-25 21:19:46
|
Sr. Price,
Thank you very much for your answer... I have tried method #1 and #2 before
and it worked, but I felt like they were not very efficient workarounds. I
can not understand the logic used in oohForm to deal with this situation. It
is my understanding that something like the feature available for "select"
fields should be implemented within oohForm, that is: the possiblity to
declare a text field as multiple, put all the values in an array and have
the oohform outputs the right thing (and also be able to understand the
form data submited back). Is it out there any solution with this approach?
i.e.
**********
$f->add_element(array("type"=>"text",
"name"=>"myField",
"multiple"=>1,
"value"=>"$values"));
***
for ($i=0;$i<$n;$i++) {
$f->show_element(myField, $values[$i]);
}
***
And then have oohForm outputs:
<input type="text" name="myField" value="$values[0]">
<input type="text" name="myField" value="$values[1]">
"
"
<input type="text" name="myField" value="$values[n]">
**********
Andres
-----Original Message-----
From: Nathaniel Price [mailto:np...@te...]
Sent: Lunes, 25 de Agosto de 2003 02:27 p.m.
To: Andres Barreto Zicare
Subject: Re: [Phplib-users] oohForm text element with multiple attribute
There have been some problems with using JavaScript on form inputs that have
"[]" in their name before. Some excellent solutions can be found in the user
contributed notes in the PHP manual:
http://www.php.net/manual/en/language.types.array.php
Basically the solutions boil down to doing one of the following:
1) Use the alternate Javascript syntax to access the form, i.e.:
document.theForm.elements["myField[0]"].value
This will only work if each input has a unique name. In other words, if you
have multiple inputs and all of them are named "myField[]", this won't work.
However, this is also the most foolproof method of doing it, since it won't
break if you move the HTML form elements around, as with method #2. All you
have to do is make sure that OOHforms outputs an index number along with
each form name, so that it looks like
<input name="myField[$i]"...> where $i is a unique number for each form
element, instead of <input name="myField[]">
2) Use the generic JavaScript elements[] array to access it, i.e.:
for (i = 0; i <= frm.elements.length; i++) {
document.theForm.elements[i].value
}
The disadvantage is that if you move your form elements around much, you'll
break your javascripts.
3) You might also experiment with using the HTML ID attribute to do it,
however I'm not sure if it will work:
<script language="javascript">
//UNTESTED JAVASCRIPT - Use at own risk
//Make sure your form elements are done like this:
//<input type="text" name="myField[]" id="myField1">
//<input type="text" name="myField[]" id="myField2">
//and so on
document.writeln(document.getElementById("myField1").value);
document.writeln(document.getElementById("myField2").value);
</script>
You will need to make sure that each HTML ID attribute is given a different
name. This one is almost like method #1, but you don't have to worry about
giving each element a unique NAME attribute.
I will leave a specific implementation within OOHforms as an excersize to
the reader, since I haven't bothered much with that particular class and
wouldn't know exactly where you'd need to modify it.
_________________________________
Nathaniel Price
Webmaster <http://www.tesseract.net>
----- Original Message -----
From: "Andres Barreto Zicare" <aba...@ei...>
To: <php...@li...>
Sent: Monday, August 25, 2003 12:30 PM
Subject: [Phplib-users] oohForm text element with multiple attribute
>
> Hello again:
> I went into the oohForm class files and I edited the line where a multiple
> text field is printed so no more problems with the appended "[]". But I
> still have a problem, it is not posible to give different values to the
> various instances of a multiple text field. By now, I wonder if I am
trying
> to do something that oohForm does not offer... Being more especific... Can
> oohForm deal with multiple text fields with the same name and different
> values?
> Thank you very much...
> Andres
>
>
>
> -----Original Message-----
> From: php...@li...
> [mailto:php...@li...]On Behalf Of Andres
> Barreto Zicare
> Sent: Viernes, 22 de Agosto de 2003 12:21 p.m.
> To: php...@li...
> Subject: [Phplib-users] oohForm text element with multiple attribute
>
>
> Hello:
>
> In Javascript, if multiple objects on the same form have the same NAME
> attribute (eg. <input type=text name=myField> ), an array of the given
NAME
> (myField) is created automatically. Elements are indexed in source order
> starting at 0. So references to document.theForm.myField[0] are valid.
>
> Now, I am using this piece of php code:
>
> for ($i=0;$i<$n;$i++)
> {
> $f->add_element(array("type"=>"text",
> "name"=>"myField",
> "multiple"=>1,
> "value"=>"$nombre"));
> }
>
> And I have found that oohform prints the form elements as: <input
> name=myField[] value=''>
>
> The "[]" appended to the element name fools the javascript interpreter so
I
> cant make reference to the elements.
>
> How can I make oohform to print the element name without the "[]" ?
>
> Thanks
>
> Andres
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines
> at the same time. Free trial click
here:http://www.vmware.com/wl/offer/358/0
> _______________________________________________
> Phplib-users mailing list
> Php...@li...
> https://lists.sourceforge.net/lists/listinfo/phplib-users
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines
> at the same time. Free trial click
here:http://www.vmware.com/wl/offer/358/0
> _______________________________________________
> Phplib-users mailing list
> Php...@li...
> https://lists.sourceforge.net/lists/listinfo/phplib-users
>
>
|