code/pagetypes/MetadataPostcardEntryPage.php
/**
     * This function creates the metdata entry form by getting the fields defined
     * for the page, in their sort order, and creating form fields for them.
     *
     * @return Form
     */
This function creates the metdata entry form by getting the fields defined
for the page, in their sort order, and creating form fields for them.

@return Form
This function creates the metdata entry form by getting the fields defined for the page in their sort order and creating form fields for them . @return Form
public function MetadataEntryForm()
    {
        $params = array_change_key_case($this->getRequest()->getVars(), CASE_LOWER);
        $hiddenFields = array();
        if (!empty($params['project_coordinator'])) {
            $hiddenFields['_Project_Coordinator'] = $params['project_coordinator'];
        } else if (!empty($params['project_administrator'])) {
            $hiddenFields['_Project_Coordinator'] = $params['project_administrator'];
        }
        if (!empty($params['project_coordinator_email'])) {
            $hiddenFields['_Project_Coordinator_email'] = $params['project_coordinator_email'];
        } else if (!empty($params['project_administrator_email'])) {
            $hiddenFields['_Project_Coordinator_email'] = $params['project_administrator_email'];
        }
        if (!empty($params['project_manager'])) {
            $hiddenFields['_Project_Manager'] = $params['project_manager'];
        }
        if (!empty($params['project_code'])) {
            $hiddenFields['_Project_Code'] = $params['project_code'];
        }
        $metadataFields = $this->Fields()->where("FieldType != 'PLACEHOLDER'")->Sort('SortOrder', 'asc');
        $formFields = FieldList::create();
        $actions = FieldList::create();
        $requiredFields = array();
        $formFields->push(
            LiteralField::create('required', '<p>* Required fields</p>')
        );
        if ($metadataFields->count()) {
            foreach($metadataFields as $field) {
                $fieldName = str_replace(' ', '_', $field->Label);
                $fieldLabel = $field->Label;
                if ($field->Required) {
                    $requiredFields[] = $fieldName;
                    $fieldLabel .= ' *';
                }
                $fieldValue = null;
                if (isset($params[strtolower($fieldName)])) {
                    $fieldValue = $params[strtolower($fieldName)];
                }
                $newField = null;
                if ($field->FieldType == 'TEXTBOX') {
                    $formFields->push($newField = TextField::create($fieldName, $fieldLabel));
                } else if ($field->FieldType == 'TEXTAREA') {
                    $formFields->push($newField = TextareaField::create($fieldName, $fieldLabel));
                } else if ($field->FieldType == 'KEYWORDS') {
                    $formFields->push($newField = TextAreaField::create($fieldName, $fieldLabel));
                    $formFields->push(LiteralField::create(
                        $fieldName . '_adminKeywords',
                        "<div class='control-group' style='margin-top: -12px'>Already specified : " . $field->KeywordsValue . "</div>"
                    ));
                } else if ($field->FieldType == 'DROPDOWN') {
                    $entries = $field->DropdownEntries()->sort('SortOrder', 'Asc')->map('Key', 'Label');
                    if ($field->DropdownOtherOption == true) {
                        $entries->push('other', 'Other');
                    }
                    $formFields->push(
                        $newField = DropdownField::create(
                            $fieldName,
                            $fieldLabel,
                            $entries
                        )->setEmptyString('Select')
                    );
                    if ($field->DropdownOtherOption == true) {
                        $formFields->push(
                            TextField::create(
                                "${fieldName}_other",
                                "Please specify the 'other'"
                            )->hideUnless($fieldName)->isEqualTo("other")->end()
                        );
                    }
                }
                if ($newField) {
                    if (!empty($field->HelpText)) {
                        $newField->setRightTitle($field->HelpText);
                    }
                    if ($field->Readonly && $fieldValue) {
                        $newField->setReadonly(true);
                    }
                    if ($fieldValue) {
                        $newField->setValue($fieldValue);
                    }
                }
            }
            $formFields->push(
                CheckboxField::create('AdditionalMessage', 'Include a message from me to the curators')
            );
            $formFields->push(
                $emailField = EmailField::create('AdditionalMessageEmail', 'My email address')
                    ->setRightTitle('Please enter your email address so the curator knows who the message below is from.')
                    ->hideUnless('AdditionalMessage')->isChecked()->end()
            );
            if (isset($params['project_manager_email'])) {
                $emailField->setValue($params['project_manager_email']);
            }
            $formFields->push(
                TextareaField::create('AdditionalMessageText', 'My message')
                    ->setRightTitle('You can enter a message here which is appended to the email sent the curator after the record has successfully been pushed to the catalogue.')
                    ->hideUnless('AdditionalMessage')->isChecked()->end()
            );
            if ($hiddenFields) {
                foreach($hiddenFields as $key => $val) {
                    $formFields->push(
                        HiddenField::create($key, '', $val)
                    );
                }
            }
            $actions = FieldList::create(FormAction::create('sendMetadataForm', 'Send'));
        } else {
            $formFields->push(
                ErrorMessage::create('No metadata entry fields have been specified for this page.')
            );
        }
        $validator = ZenValidator::create();
        $validator->addRequiredFields($requiredFields);
        $form = Form::create($this, 'MetadataEntryForm', $formFields, $actions, $validator);
        $data = Session::get("FormData.{$form->getName()}.data");
        return $data ? $form->loadDataFrom($data) : $form;
    }
public function MetadataEntryForm ( ) { $ params = array_change_key_case ( $ this -> getRequest ( ) -> getVars ( ) , CASE_LOWER ) ; $ hiddenFields = array ( ) ; if ( ! empty ( $ params [ 'project_coordinator' ] ) ) { $ hiddenFields [ '_Project_Coordinator' ] = $ params [ 'project_coordinator' ] ; } else if ( ! empty ( $ params [ 'project_administrator' ] ) ) { $ hiddenFields [ '_Project_Coordinator' ] = $ params [ 'project_administrator' ] ; } if ( ! empty ( $ params [ 'project_coordinator_email' ] ) ) { $ hiddenFields [ '_Project_Coordinator_email' ] = $ params [ 'project_coordinator_email' ] ; } else if ( ! empty ( $ params [ 'project_administrator_email' ] ) ) { $ hiddenFields [ '_Project_Coordinator_email' ] = $ params [ 'project_administrator_email' ] ; } if ( ! empty ( $ params [ 'project_manager' ] ) ) { $ hiddenFields [ '_Project_Manager' ] = $ params [ 'project_manager' ] ; } if ( ! empty ( $ params [ 'project_code' ] ) ) { $ hiddenFields [ '_Project_Code' ] = $ params [ 'project_code' ] ; } $ metadataFields = $ this -> Fields ( ) -> where ( " FieldType != 'PLACEHOLDER' " ) -> Sort ( 'SortOrder' , 'asc' ) ; $ formFields = FieldList :: create ( ) ; $ actions = FieldList :: create ( ) ; $ requiredFields = array ( ) ; $ formFields -> push ( LiteralField :: create ( 'required' , '<p>* Required fields</p>' ) ) ; if ( $ metadataFields -> count ( ) ) { foreach ( $ metadataFields as $ field ) { $ fieldName = str_replace ( ' ' , '_' , $ field -> Label ) ; $ fieldLabel = $ field -> Label ; if ( $ field -> Required ) { $ requiredFields [ ] = $ fieldName ; $ fieldLabel .= ' *' ; } $ fieldValue = null ; if ( isset ( $ params [ strtolower ( $ fieldName ) ] ) ) { $ fieldValue = $ params [ strtolower ( $ fieldName ) ] ; } $ newField = null ; if ( $ field -> FieldType == 'TEXTBOX' ) { $ formFields -> push ( $ newField = TextField :: create ( $ fieldName , $ fieldLabel ) ) ; } else if ( $ field -> FieldType == 'TEXTAREA' ) { $ formFields -> push ( $ newField = TextareaField :: create ( $ fieldName , $ fieldLabel ) ) ; } else if ( $ field -> FieldType == 'KEYWORDS' ) { $ formFields -> push ( $ newField = TextAreaField :: create ( $ fieldName , $ fieldLabel ) ) ; $ formFields -> push ( LiteralField :: create ( $ fieldName . '_adminKeywords' , " <div class='control-group' style='margin-top: -12px'>Already specified :  " . $ field -> KeywordsValue . " </div> " ) ) ; } else if ( $ field -> FieldType == 'DROPDOWN' ) { $ entries = $ field -> DropdownEntries ( ) -> sort ( 'SortOrder' , 'Asc' ) -> map ( 'Key' , 'Label' ) ; if ( $ field -> DropdownOtherOption == true ) { $ entries -> push ( 'other' , 'Other' ) ; } $ formFields -> push ( $ newField = DropdownField :: create ( $ fieldName , $ fieldLabel , $ entries ) -> setEmptyString ( 'Select' ) ) ; if ( $ field -> DropdownOtherOption == true ) { $ formFields -> push ( TextField :: create ( " $ { fieldName } _other " , " Please specify the 'other' " ) -> hideUnless ( $ fieldName ) -> isEqualTo ( " other " ) -> end ( ) ) ; } } if ( $ newField ) { if ( ! empty ( $ field -> HelpText ) ) { $ newField -> setRightTitle ( $ field -> HelpText ) ; } if ( $ field -> Readonly && $ fieldValue ) { $ newField -> setReadonly ( true ) ; } if ( $ fieldValue ) { $ newField -> setValue ( $ fieldValue ) ; } } } $ formFields -> push ( CheckboxField :: create ( 'AdditionalMessage' , 'Include a message from me to the curators' ) ) ; $ formFields -> push ( $ emailField = EmailField :: create ( 'AdditionalMessageEmail' , 'My email address' ) -> setRightTitle ( 'Please enter your email address so the curator knows who the message below is from.' ) -> hideUnless ( 'AdditionalMessage' ) -> isChecked ( ) -> end ( ) ) ; if ( isset ( $ params [ 'project_manager_email' ] ) ) { $ emailField -> setValue ( $ params [ 'project_manager_email' ] ) ; } $ formFields -> push ( TextareaField :: create ( 'AdditionalMessageText' , 'My message' ) -> setRightTitle ( 'You can enter a message here which is appended to the email sent the curator after the record has successfully been pushed to the catalogue.' ) -> hideUnless ( 'AdditionalMessage' ) -> isChecked ( ) -> end ( ) ) ; if ( $ hiddenFields ) { foreach ( $ hiddenFields as $ key => $ val ) { $ formFields -> push ( HiddenField :: create ( $ key , '' , $ val ) ) ; } } $ actions = FieldList :: create ( FormAction :: create ( 'sendMetadataForm' , 'Send' ) ) ; } else { $ formFields -> push ( ErrorMessage :: create ( 'No metadata entry fields have been specified for this page.' ) ) ; } $ validator = ZenValidator :: create ( ) ; $ validator -> addRequiredFields ( $ requiredFields ) ; $ form = Form :: create ( $ this , 'MetadataEntryForm' , $ formFields , $ actions , $ validator ) ; $ data = Session :: get ( " FormData. { $ form -> getName ( ) } .data " ) ; return $ data ? $ form -> loadDataFrom ( $ data ) : $ form ; }
This function creates the metdata entry form by getting the fields defined
 for the page, in their sort order, and creating form fields for them.
This function creates the metdata entry form by getting the fields defined for the page in their sort order and creating form fields for them .
// NIWA are worried about parameter case and would like it case insensitive so convert all get vars to lower // I think this is because they are not 100% what case the parameters from oracle will be in. // Check in the parameters sent to this page if there are certian fields needed to power the // functionality which emails project coordinators and if so get them as we will need to add // them to the bottom of the form as hidden fields, this way we can access them in the form // processing and send the email. // These 2 fields can be populated either by Project_Coordinator or Project_Administrator as Oracle actually // sends Project_Administrator. NIWA want to keep the field here called coordinator. // Get the fields defined for this page, exclude the placeholder fields as they are not displayed to the user. // Create fieldfield for the form fields. // Push the required fields message as a literal field at the top. // Create a version of the label with spaces replaced with underscores as that is how // any paraemters in the URL will come (plus we can use it for the field name) // If the field is required then add it to the required fields and also add an // asterix to the end of the field label. // Check if there is a parameter in the GET vars with the corresponding name. // Define a var for the new field, means no matter the type created // later on in the code we can apply common things like the value. // Single line text field creation. // If keywords then output 2 fields the textbox for the keywords and then also a // literal read only list of those already specified by the admin below. // Some dropdowns have an 'other' option so must add the 'other' to the entries // and also have a conditionally displayed text field for when other is chosen. //++ @TODO // Ideally if the dropdown is required then if other is selected the other field // should also be required. Unfortunatley the conditional validation logic of ZEN // does not work in the front end - so need to figure out how to do this. // If a new field was created then set some things on it which are common no matter the type. // Set help text for the field if defined. // Field must only be made readonly if the admin specified that they should be // provided that a value was specified in the URL for it. // Set the value of the field one was plucked from the URL params. // Add fields to the bottom of the form for the user to include a message in the email sent to curators // this is entirely optional and will not be used in most cases so is hidden until a checkbox is ticked. // For the email address, because its project managers filling out the form, check if the Project_Manager_email // has been specified in the URL params and if so pre-populate the field with that value. // If there are any hidden fields then loop though and add them as hidden fields to the bottom of the form. // We have at least one field so set the action for the form to submit the entry to the catalogue. // Set up the required fields validation. // Create form. // Check if the data for the form has been saved in the session, if so then populate // the form with this data, if not then just return the default form.