Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Form behavior in Custom Template

Go to End

2 Posts   1583 Views


Community Member, 19 Posts

12 January 2012 at 3:02pm

Edited: 12/01/2012 3:05pm

I have been working hard on a form and had it working before applying a custom template. The form takes donor information and writes it to an XML file, then sends the user along to their destination to pay. It was working in it's default layout but now execute the XMLWrite function I created.

DonationForm.php -

// Donation Form for PNWU
class DonationForm extends Form {

//Define our form function as allowed
static $allowed_actions = array(

function DonationForm($controller, $name) {

//Create Fields
$fields = new FieldSet(
new OptionsetField('Prefix', null, array('Mrs' => 'Mr.', 'Mrs.' => 'Mrs.', 'Ms.' => 'Ms.', 'Dr.' => 'Dr.')),
new TextField('FirstName', 'First Name*'),
new TextField('LastName', 'Last Name*'),
new TextField('MI', 'Initial'),
new TextField('SpouseFirst', 'Spouse, First Name*'),
new TextField('SpouseLast', 'Last Name'),
new TextField('SpouseMI', 'Initial'),
new OptionsetField('Type', null, array('Home' => 'Home', 'Business' => 'Business')),
new TextField('Occupation', 'Occupation'),
new TextField('Suffix', 'Suffix'),
new TextField('Business', 'Business Name'),
new TextField('Address', 'Full Address*'),
new TextField('City', 'City'),
new TextField('State', 'State'),
new TextField('Zip', 'Zipcode'),
new NumericField('Phone', 'Home Phone* (No Dashes)', null, 10),
new NumericField('BusinessPh', 'Business Phone', null, 10),
new NumericField('MobilePh', 'Mobile Phone', null, 10),
new EmailField('Email', 'Email Address*'),
//Amount Information
new OptionsetField('GiftType', null, array('OneTime' => null, 'Recurring' => null)),
new CurrencyField('BaseAmount', 'Amount of Donation'),
new CurrencyField('RecurringAmount', 'Recurring Amount'),
new NumericField('Years', 'years', null, 5),
new CurrencyField('MonthlyAmount', null),
new TextField('Month', null),
new TextField('Year', null),
new CurrencyField('InstallAmount', null),
new CheckboxField('RemindMe', null),
new TextField('DisplayAs', null),
new DropdownField('PaymentType', 'Select Your Payment Method', array('CC' => 'Credit Card', 'ACH' => 'Check'))
if(isset($_GET['confirm'])) {
echo $xmlfile;

// Create action
$actions = new FieldSet(
new FormAction('XMLWrite', 'Submit')

// Create action
$requiredFields = new RequiredFields('FirstName', 'LastName', 'Email', 'Address', 'HomePhone', 'PaymentType', 'CardNumber', 'Month', 'Year', 'CVV2');

parent::__construct($controller, $name, $fields, $actions, $requiredFields);


function XMLWrite() {
//Write to Donation.xml
//Convert Form data to variables
$name = $_POST['FirstName'] . $_POST['LastName'];
$business = $_POST['Business'];
$address = $_POST['Address'];
$address2 = $_POST['Address2'];
$city = $_POST['City'];
$state = $_POST['State'];
$zip = $_POST['Zip'];
$homePhone = $_POST['HomePhone'];
$cellPhone = $_POST['CellPhone'];
$email = $_POST['Email'];
$giftType = $_POST['GiftType'];
$paymentType = 'CC';
$cardNumber = $_POST['CardNumber'];
$expiration = $_POST['Month'] . '/' . $_POST['Year'];
$CVV2 = $_POST['CVV2'];
$securityID = $_POST['SecurityID'];
// Amount Information

$xmlfile = "../assets/OfficialPayments/" . $name . $paymentType . ".xml";
$file = fopen($xmlfile,"w");

$xml_document = '<?xml version="1.0" encoding="utf-8"?>
<Payment xmlns:xsi="" xmlns:xsd="">
<UniqueID />
<BaseAmount>' . $amount . '</BaseAmount>
<DisplayTerms />
<ItemID />
<PaymentMethod>'. $paymentType .'</PaymentMethod>

fwrite($file, $xml_document);

/*public function FormAttributes() {

if(!isset($_GET['confirm'])) {
$attr = parent::FormAttributes();
// Do your manipulations
$attr = 'id="DonationForm_DonationForm" action="http://localhost/pnwu/home/new-testpage/?confirm=1" method="post" enctype="application/x-www-form-urlencoded"';
return $attr;
} else if(isset($_GET['confirm']) && $_GET['confirm'] == '1') {
$attr = parent::FormAttributes();
// Do your manipulations
$attr = 'id="DonationForm_DonationForm" action="https://remoteWebsite/payselect/payselect_epayprocessor.asmx" method="post" enctype="application/x-www-form-urlencoded"';
return $attr;

function forTemplate() {

return $this->renderWith(array(


} -

<% require javascript( ) %>
<div id="text2">
<form $FormAttributes>
<h3 align="center">Donor Information</h3>
<table cellpadding="4">
<td colspan="4">$dataFieldByName(Prefix)</td>
<td><label>First Name: </label>$dataFieldByName(FirstName)</td>
<td colspan="2"><label>Last Name: </label>$dataFieldByName(LastName)</td>
<td align="right"><label>Initial: </label>$dataFieldByName(MI)</td>
<td><label>Spouse, First Name: </label>$dataFieldByName(SpouseFirst)</td>
<td colspan="2"><label>Last Name: </label>$dataFieldByName(SpouseLast)</td>
<td align="right"><label>Initial: </label>$dataFieldByName(SpouseMI)</td>
<td>Is this $dataFieldByName(Type) information?</td>
<td colspan="3" align="right"><label>Name of Business: $dataFieldByName(Business)</td>
<td><label>Occupation: </label>$dataFieldByName(Occupation)</td>
<td><label>Title/Suffix: </label>$dataFieldByName(Suffix)</td>
<td colspan="2" align="right"><label>Email: </label>$dataFieldByName(Email)</td>
<td><label>Address: </label>$dataFieldByName(Address)</td>
<td><label>City: </label>$dataFieldByName(City)</td>
<td><label>State: </label>$dataFieldByName(State)</td>
<td align="right"><label>Zip: </label>$dataFieldByName(Zip)</td>
<td><label>Phone: </label>$dataFieldByName(Phone)</td>
<td colspan="2"><label>(Business) </label>$dataFieldByName(BusinessPh)</td>
<td align="right"><label>(Mobile) </label>$dataFieldByName(MobilePh)</td>
<h3 align="center">Donation Details</h3>
<table background="#a0a0a0">
<td rowspan="2">$dataFieldByName(GiftType)</td>
<td>One-time <i>cash</i> gift.</td>
<td>Pledge, to be paid over a period of $dataFieldByName(Years) years.</td>
<td align="right" colspan="2">First Payment of $dataFieldByName(MonthlyAmount)</td>
<td> will be made (month) $dataFieldByName(Month) of (year) $dataFieldByName(Year)</td>
<td align="left" colspan="2">In equal installments of $dataFieldByName(InstallAmount)</td>
<td>$dataFieldByName(RemindMe) Please send me pledge reminders.
<td colspan="3">&nbsp;</td>
<td colspan="3">Please indicate how your name(s) should appear on our published list of donors: <br />$dataFieldByName(DisplayAs)</td>
<td colspan="3">&nbsp;</td>
<td colspan="2" align="right">$dataFieldByName(PaymentType)</td>
<td><% control actions %>$Field<% end_control %></td>

Sorry for the length but I couldn't attach the files.


Community Member, 19 Posts

13 January 2012 at 2:04pm

A little more on the subject. It appears that by creating the form template and adding the fields this way, the action that is applied via the "submit" button is not being called. In this case, the XMLWrite function is not being run. I tested by removing the rest of the code and just used:
Director::redirect(Director::baseURL() . $this->URLSegment . "/?confirm=1");

The redirect did not happen. Anyone know why the $action is not working?