#1951 - Fix newsletter subscription form

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@49174 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-02-07 03:00:25 +00:00
parent 2128298467
commit 0ad6198307
2 changed files with 14 additions and 15 deletions

View File

@ -65,14 +65,19 @@ class SubscribeForm extends UserDefinedForm {
$newField->prepopulate( $typeValue );
}
$newField->setField('ID', "new-" . $count);
$newField->ParentID = $this->ID;
$newField->Sort = $count;
$f->addWithoutWrite($newField);
$newField->write();
$count++;
}
}
public function write($showDebug = false, $forceInsert = false, $forceWrite = false) {
$isNew = (!$this->ID);
parent::write($showDebug, $forceInsert, $forceWrite);
if($isNew) $this->addDefaultFields();
}
public function Newsletters() {
$components = $this->getComponents('Newsletters');
return $components;
@ -179,7 +184,6 @@ class SubscribeForm_SubscribeEmail extends Email_Template {
class SubscribeForm_Controller extends UserDefinedForm_Controller {
function process( $data, $form ) {
// Add the user to the mailing list
$member = Object::create("Member");
@ -188,7 +192,6 @@ class SubscribeForm_Controller extends UserDefinedForm_Controller {
// map the editables to the data
foreach( $this->Fields() as $editable ) {
$field = $editable->CustomParameter;
if( !$field )
continue;
@ -205,7 +208,7 @@ class SubscribeForm_Controller extends UserDefinedForm_Controller {
$newsletters = array();
// Add member to the selected newsletters
if( $data['Newsletters'] ) foreach( $data['Newsletters'] as $listID ) {
if( isset($data['Newsletters'])) foreach( $data['Newsletters'] as $listID ) {
if( !is_numeric( $listID ) )
continue;
@ -259,13 +262,9 @@ class SubscribeForm_Controller extends UserDefinedForm_Controller {
$newsletters = array();
// Debug::show($newsletterList);
// get the newsletter types to display on the form
foreach( $newsletterList as $newsletter )
$newsletters[] = $newsletter;
// Debug::show( $newsletters );
$newsletters[$newsletter->ID] = $newsletter->Title;
$form->Fields()->push( new CheckboxSetField( 'Newsletters', 'Subscribe to lists', $newsletters ) );

View File

@ -232,7 +232,7 @@ class UserDefinedForm_Controller extends Page_Controller {
if( $field->hasMethod( 'getValueFromData' ) )
$submittedField->Value = $field->getValueFromData( $data );
else
$submittedField->Value = $data[$field->Name];
if(isset($data[$field->Name])) $submittedField->Value = $data[$field->Name];
$submittedField->write();
$submittedFields->push($submittedField);
@ -278,7 +278,7 @@ class UserDefinedForm_Controller extends Page_Controller {
$values[$field->Title] = Convert::linkIfMatch($field->getValueFromData( $data ));
} else {
$values[$field->Title] = Convert::linkIfMatch($data[$field->Name]);
if(isset($data[$field->Name])) $values[$field->Title] = Convert::linkIfMatch($data[$field->Name]);
}
}