I have the form 'usertests' with three fields: 'Competency name', 'Course','Test' and two buttons: 'Submit' and 'Add test'. I need to assign a custom function('add_test()') to the button 'Add test'. When a user clicks the 'Add test' button two new fields('Course' and 'Test') are added to the form. I do not understand how to assign custom function to the button. Anybody knows?
Hi Viktor, Take a look at repeat elements, I think that shoud do what you want.
Hi Mark! Thanks for your answer. I know about 'repeat elements'. I can make it. it is not clear to me exactly how to associate an event with a button that calls the function of creating elements. I do not understand how to implement the button itself. Do you understand me???
It's been a while since I've done it myself, but I dont think you need to create the button. If you add at $this->repeat_elements()
to your form defintion, it will create a "Add xx more" button for you.
Yes it is that! thanks a lot, Mark
What about a button for deleting added fields??
Hmm, I'm not sure about that. I know that empty repeated elements should be ignored, but I dont know about removing them once they've been added.
or it requires a new discussion theme?