10390 Posts in 2200 Topics by 1713 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1459 Views |
-
Userforms - add default fields to form

30 September 2009 at 2:29pm
Hi,
how do you add default fields to a page that is extending userdefinedforms.
Wanted Scenario eg.
Admin creates a new event page type and the form tab automatically has two form elements. Eg. a 'RSVP' checkbox and a 'Name' text field.Current Problem.
Currently everytime admin creates a new Event Page type, he/she has to manually add the fields to the form (not so good when you have lots of events all the time)Im sure its simple, but cant find the answer. Iv looked at newsletter subscibeform that does this but i get errors trying to mimic it!
-
Re: Userforms - add default fields to form

30 September 2009 at 3:33pm
You would need to subclass userformpage.php as you can't do this out of the box. Then one way you could do this is on your subclass override the onAfterWrite() function to create the fields. I am pretty sure this will be called when you create the page
// your userformpage subclass file
function onAfterWrite() {
if(!$this->Fields() || !$this->Fields()->exists()) {
$textField = new EditableTextField();
$textField->ParentID = $this->ID;
// set any other options
$textField->write();
$this->Fields()->push($textField);}
parent::onAfterWrite();
} -
Re: Userforms - add default fields to form

30 September 2009 at 4:11pm Last edited: 30 September 2009 8:11pm
thanks will, I appreciate your help but that went all over my head!
could you please explain it in basic idiot proof terms...
I have
class EventPage extends UserDefinedForm{
//Removed non-important code for this post
// your userformpage subclass file
function onAfterWrite() {
if(!$this->Fields() || !$this->Fields()->exists()) {
$textField = new EditableTextField();
$textField->ParentID = $this->ID;
// set any other options
$textField->write();
$this->Fields()->push($textField);}
parent::onAfterWrite();
}}
But still i have to manually create the form when i click on the form tab for each new eventpage. Please help me ive spent all day on this and still stuck!
-
Re: Userforms - add default fields to form

22 October 2009 at 2:01pm
Hi mate,
I have just done this exact thing by simply creating a page type that extends userdefined forms. Will is right in that onAfterWrite will do this for you.
My needs were to populate alot more defaults than what "new EditableTextField" would provide (not to mention other field types) so I added a few functions.
Attached is my code for this default form. The setup for the fields is done from line 61 onwards.
Hope it helps.
Aaron
| 1459 Views | ||
|
Page:
1
|
Go to Top |



