function getCMSFields()
 {
     $fields = new FieldSet(new TextField('SearchPhrase', 'Search For'), new TextField('SearchTitle', 'Title'), new TextField('SearchSubject', 'Subject'));
     $fields->merge(parent::getCMSFields());
     $fields->removeByName('TwitterUser');
     return $fields;
 }
 /**
  * @param object $controller Controller instance
  * @param string $name The form name
  */
 public function __construct($controller, $name)
 {
     $member = Member::currentUserID() ? Member::currentUser() : new Member();
     $order = singleton('Order');
     $fields = new FieldSet($billingFields = $member->billingDetailsFields(), $shippingFields = $order->shippingDetailsFields());
     $fields->merge(Payment::combined_form_fields($order->Total()));
     $actions = new FieldSet(new FormAction('doProcess', _t('OrderForm.PLACEORDER', 'Place order and make payment')));
     parent::__construct($controller, $name, $fields, $actions);
     if ($member->exists()) {
         $this->loadDataFrom($member);
     }
 }
Ejemplo n.º 3
0
	/**
	 * Build a FieldSet of the FormAction fields for the given step.
	 * 
	 * If the current step is the final step, we push in a submit button, which
	 * calls the action {@link finish()} to finalise the submission. Otherwise,
	 * we push in a next button which calls the action {@link next()} to determine
	 * where to go next in our step process, and save any form data collected.
	 * 
	 * If there's a previous step (a step that has the current step as it's next
	 * step class), then we allow a previous button, which calls the previous action
	 * to determine which step to go back to.
	 * 
	 * If there are any extra actions defined in MultiFormStep->getExtraActions()
	 * then that set of actions is appended to the end of the actions FieldSet we
	 * have created in this method.
	 * 
	 * @param $currentStep Subclass of MultiFormStep
	 * @return FieldSet of FormAction objects
	 */
	function actionsFor($step) {
		// Create default multi step actions (next, prev), and merge with extra actions, if any
		$actions = new FieldSet();
		
		// If the form is at final step, create a submit button to perform final actions
		// The last step doesn't have a next button, so add that action to any step that isn't the final one
		if($step->isFinalStep()) {
			$actions->push(new FormAction('finish', _t('MultiForm.SUBMIT', 'Submit')));
		} else {
			$actions->push(new FormAction('next', _t('MultiForm.NEXT', 'Next')));
		}
		
		// If there is a previous step defined, add the back button
		if($step->getPreviousStep() && $step->canGoBack()) {
			// If there is a next step, insert the action before the next action
			if($step->getNextStep()) {
				$actions->insertBefore(new FormAction('prev', _t('MultiForm.BACK', 'Back')), 'action_next');
			// Assume that this is the last step, insert the action before the finish action
			} else {
				$actions->insertBefore(new FormAction('prev', _t('MultiForm.BACK', 'Back')), 'action_finish');
			}
		}

		// Merge any extra action fields defined on the step
		$actions->merge($step->getExtraActions());
		
		return $actions;
	}
 function getCMSFields()
 {
     $fields = new FieldSet(new TextField('FavesTitle', 'Title'), new TextField('FavesSubject', 'Subject'));
     $fields->merge(parent::getCMSFields());
     return $fields;
 }
 function __construct($controller, $name)
 {
     //requirements
     Requirements::javascript('ecommerce/javascript/EcomOrderFormAddress.js');
     // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         Requirements::javascript('ecommerce/javascript/EcomOrderFormShipping.js');
         // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     }
     //set basics
     $order = ShoppingCart::current_order();
     $requiredFields = array();
     //  ________________ 1) Member + Address fields
     //find member
     $this->orderMember = $order->CreateOrReturnExistingMember(false);
     $this->loggedInMember = Member::currentUser();
     //strange security situation...
     if ($this->orderMember->exists() && $this->loggedInMember) {
         if ($this->orderMember->ID != $this->loggedInMember->ID) {
             if (!$this->loggedInMember->IsShopAdmin()) {
                 $this->loggedInMember->logOut();
             }
         }
     }
     $addressFieldsBilling = new FieldSet();
     //member fields
     if ($this->orderMember) {
         $memberFields = $this->orderMember->getEcommerceFields();
         $requiredFields = array_merge($requiredFields, $this->orderMember->getEcommerceRequiredFields());
         $addressFieldsBilling->merge($memberFields);
     }
     //billing address field
     $billingAddress = $order->CreateOrReturnExistingAddress("BillingAddress");
     $billingAddressFields = $billingAddress->getFields($this->orderMember);
     $requiredFields = array_merge($requiredFields, $billingAddress->getRequiredFields());
     $addressFieldsBilling->merge($billingAddressFields);
     //shipping address field
     $addressFieldsShipping = null;
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $addressFieldsShipping = new FieldSet();
         //add the important CHECKBOX
         $useShippingAddressField = new FieldSet(new CheckboxField("UseShippingAddress", _t("OrderForm.USESHIPPINGADDRESS", "Use an alternative shipping address")));
         $addressFieldsShipping->merge($useShippingAddressField);
         //now we can add the shipping fields
         $shippingAddress = $order->CreateOrReturnExistingAddress("ShippingAddress");
         $shippingAddressFields = $shippingAddress->getFields($this->orderMember);
         //we have left this out for now as it was giving a lot of grief...
         //$requiredFields = array_merge($requiredFields, $shippingAddress->getRequiredFields());
         //finalise left fields
         $addressFieldsShipping->merge($shippingAddressFields);
     }
     $leftFields = new CompositeField($addressFieldsBilling);
     $leftFields->setID('LeftOrderBilling');
     $allLeftFields = new CompositeField($leftFields);
     $allLeftFields->setID('LeftOrder');
     if ($addressFieldsShipping) {
         $leftFieldsShipping = new CompositeField($addressFieldsShipping);
         $leftFieldsShipping->setID('LeftOrderShipping');
         $allLeftFields->push($leftFieldsShipping);
     }
     //  ________________  2) Log in / vs Create Account fields - RIGHT-HAND-SIDE fields
     $rightFields = new CompositeField();
     $rightFields->setID('RightOrder');
     //to do: simplify
     if (EcommerceConfig::get("EcommerceRole", "allow_customers_to_setup_accounts")) {
         if ($this->orderDoesNotHaveFullyOperationalMember()) {
             //general header
             if (!$this->loggedInMember) {
                 $rightFields->push(new LiteralField('MemberInfo', '<p class="message good">' . _t('OrderForm.MEMBERINFO', 'If you are already have an account then please') . " <a href=\"Security/login/?BackURL=" . urlencode($controller->Link()) . "\">" . _t('OrderForm.LOGIN', 'log in') . '</a>.</p>'));
             }
             $passwordField = new ConfirmedPasswordField('Password', _t('OrderForm.PASSWORD', 'Password'));
             //login invite right on the top
             if (EcommerceConfig::get("EcommerceRole", "automatic_membership")) {
                 $rightFields->push(new HeaderField('CreateAnAccount', _t('OrderForm.CREATEANACCONTOPTIONAL', 'Create an account (optional)'), 3));
                 //allow people to purchase without creating a password
                 $passwordField->setCanBeEmpty(true);
             } else {
                 $rightFields->push(new HeaderField('SetupYourAccount', _t('OrderForm.SETUPYOURACCOUNT', 'Setup your account'), 3));
                 //dont allow people to purchase without creating a password
                 $passwordField->setCanBeEmpty(false);
             }
             $requiredFields[] = 'Password[_Password]';
             $requiredFields[] = 'Password[_ConfirmPassword]';
             Requirements::customScript('jQuery("#ChoosePassword").click();', "EommerceChoosePassword");
             // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
             $rightFields->push(new LiteralField('AccountInfo', '<p>' . _t('OrderForm.ACCOUNTINFO', 'Please <a href="#Password" class="choosePassword">choose a password</a>; this will allow you can log in and check your order history in the future.') . '</p>'));
             $rightFields->push(new FieldGroup($passwordField));
         } else {
             if ($this->loggedInMember) {
                 $rightFields->push(new LiteralField('LoginNote', "<p class=\"message good\">" . _t("Account.LOGGEDIN", "You are logged in as ") . $this->loggedInMember->FirstName . ' ' . $this->loggedInMember->Surname . ' (' . $this->loggedInMember->Email . ').</p>'));
             }
         }
         if ($this->orderMember->exists()) {
             if ($this->loggedInMember) {
                 if ($this->loggedInMember->ID != $this->orderMember->ID) {
                     $rightFields->push(new LiteralField('OrderAddedTo', "<p class=\"message good\">" . _t("Account.ORDERADDEDTO", "Order will be added to ") . $this->orderMember->FirstName . ' ' . $this->orderMember->Surname . ' (' . $this->orderMember->Email . ').</p>'));
                 }
             }
         }
     }
     //  ________________  5) Put all the fields in one FieldSet
     $fields = new FieldSet($rightFields, $allLeftFields);
     //  ________________  6) Actions and required fields creation + Final Form construction
     $nextButton = new FormAction('saveAddress', _t('OrderForm.NEXT', 'Next'));
     $nextButton->addExtraClass("next");
     $actions = new FieldSet($nextButton);
     $validator = new OrderFormAddress_Validator($requiredFields);
     //TODO: do we need this here?
     $validator->setJavascriptValidationHandler("prototype");
     parent::__construct($controller, $name, $fields, $actions, $validator);
     //extensions need to be set after __construct
     if ($this->extend('updateFields', $fields) !== null) {
         $this->setFields($fields);
     }
     if ($this->extend('updateActions', $actions) !== null) {
         $this->setActions($actions);
     }
     if ($this->extend('updateValidator', $validator) !== null) {
         $this->setValidator($validator);
     }
     //  ________________  7)  Load saved data
     //we do this first so that Billing and Shipping Address can override this...
     if ($this->orderMember) {
         $this->loadDataFrom($this->orderMember);
     }
     if ($order) {
         $this->loadDataFrom($order);
         if ($billingAddress) {
             $this->loadDataFrom($billingAddress);
         }
         if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
             if ($shippingAddress) {
                 $this->loadDataFrom($shippingAddress);
             }
         }
     }
     //allow updating via decoration
     $this->extend('updateOrderFormAddress', $this);
 }