Hello.
I'm trying to create a form where the visitor of the website can buy a book/catalog. The visitor should be able to choose which of these catalogs he wants by selecting one or more checkboxes. Next to each checkbox there should be a thumbnail image of the appropriate catalog. The person who will fill the website with content later in the cms should be able to upload or change these images. There will be a limited number of catalogs (two exists already - a few will follow soon), so for now I need only five checkboxes which should only appear if an appropriate image is uploaded. I tried to implement it like this:
in the php-file:
static $db = array(
'Mailto' => 'Varchar(100)',
'SubmitText' => 'Text',
'Shop' => 'HTMLText',
'Book1Txt' => 'Text',
'Book2Txt' => 'Text',
'Book3Txt' => 'Text',
'Book4Txt' => 'Text',
'Book5Txt' => 'Text'
);
(…)
function ContactForm() {
$book1 = $this->Book1();
$book2 = $this->Book2();
$book3 = $this->Book3();
$book4 = $this->Book4();
$book5 = $this->Book5();
if (!empty($book1)) {$book1 = $this->Book1()->CroppedImage(200,200)->getURL();}
if (!empty($book2)) {$book2 = $this->Book2()->CroppedImage(200,200)->getURL();}
if (!empty($book3)) {$book3 = $this->Book3()->CroppedImage(200,200)->getURL();}
if (!empty($book4)) {$book4 = $this->Book4()->CroppedImage(200,200)->getURL();}
if (!empty($book5)) {$book5 = $this->Book5()->CroppedImage(200,200)->getURL();}
$fields = new FieldSet(
new CheckboxSetField(
$name = "Books",
$title = "Bitte wählen Sie mindestens ein Buch aus",
$source = array(
"1" => "<img src='$book1' />",
"2" => "<img src='$book2' />",
"3" => "<img src='$book3' />",
"4" => "<img src='$book4' />",
"5" => "<img src='$book5' />"
),
$value = "1"
),
new TextField('Name', 'Name*'),
new TextField('Firstname', 'Vorname*'),
new TextField('Adress', 'Adresse*'),
new EmailField('Mail', 'Email*'),
new TextareaField('Comments','Kommentar*')
);
// Create action
$actions = new FieldSet(
new FormAction('SendContactForm', 'Send')
);
// Create Validators
$validator = new RequiredFields('Name', 'Firstname', 'Adress', 'Mail');
return new Form($this, 'ContactForm', $fields, $actions, $validator);
}
and in my Template:
<div id="Content" class="typography">
<% if Success %>
$SubmitText
<% else %>
$ContactForm
<% end_if %>
</div>
But this doesn't seem to work..I always get this error:
"Fatal error: Call to a member function getURL() on a non-object in (...)"
However, I am not good enough in PHP and SilverStripe and do not know how to solve this..can anyone help me, please?