Expand my Community achievements bar.

Dinamically change the name of a field.

Avatar

Former Community Member

Dear all,

Here is my problem.

I have a 3 text fields wraped in a subform.

I have also created a button so I can add new instance of this sub form at runtime.

All that works nice.

However, I also have a HTML subbmit button, and when I submit the form to my script, I only get the last instance of the fields in the subform mentioned above.

I am not sure what is the best solution for that.

I thought that on option is if while adding the new instances of the subform, I can also dinamically change the name of the fields, so for example

in the first instance of the subform I will have fieldname2 then in the second I will have fieldname2 and then when I submit I will get both, not just the last one.

But apperantly I do not know how to dinamically change the name of the field as well.

Any help will be really realy helpful

Thank you very much

Tsvyatko

Senior Datbase Manager

Columbia University

2 Replies

Avatar

Former Community Member

Hi ,

Name of the field is nothing but caption of the field .

Try the below javascript  code to change the name of the field dynamically .

xfa.resolveNode("TextField1.caption.value.#text").value = "TextField2";

All the best.

Regards,

Dhiyan

Avatar

Former Community Member

Hi Dhiyan,

Thanks for raplying.

Your suggestion does work in the way that id does change the caption of the fields dinamically.

However, looks like when I use the HTML submit button the form still submits the data only in the last fields of the repeated subform and their names have not changed.

Probably when you say that the name of the field is its caption you mean just a static text. But I am refearing to fields where you can enter data inside.

Basically, what I am trying to do, is to be able to dinamically create a table in my acrobat form.

This table has let say 2 fields: InstanceNumber and YearOccured.

So when I lets say add 3 instances in my acrobat form, I want to user to click an HTML submit button, and then through a PHP script I can submit all the 3 instance to a database.

However, when I check the REQUEST array, I only see these 2 fields once (instead of 3 times) and they contain the data of the last added row.

I assume that the problem could be solved if I can somehow change their names while I add rows.

So for example in the first row I will have:

InstanceNumber_1 and YearOccured_1

in the second:

InstanceNumber_2 and YearOccured_2

and in third

InstanceNumber_3 and YearOccured_3

And so when I submit the form it will submit the data of all the rows.

I am not sure if that is possible though. But definatelly I do not know how to do it ))

What I did to go around this is:

I have created 2 other (hidden) fields.

And when I click the submit button, before I do the actuall submit, I take the data from all 3 rows one by one and I put i in this hidded fields as (tab) delimited. And so now I have in my REQUEST array all the data from all 3 rows, in a single tab delimited field. And then I can work it out from there with PHP to submit it where ever.

However, I was hoping for some little more elegant solution, that is if I can change the names and so have all the fields data submitted. Or any other good suggestion

If anyone knows, will buy you a beer )

Thanks again

Tsvyatko