Good point!
OK my Advert DO has this:
public static $has_one = array(
"Advertiser" => "Member",
"Category" => "Category",
"Pic" => "Image"
);
My AddAdvert function Form() has the following code:
public function Form() {
$fields = singleton('Advert')->getFrontEndFields();
$fields->removeByName("Content");
$fields->removeByName("Moderated");
$fields->removeByName("AdvertiserID");
$fields->removeByName("Reported");
$fields->add(new AdvertContentField("Content", "Advert Text"));
$categoryField = $fields->fieldByName("CategoryID");
$categoryField->setEmptyString("General / No Category");
if (!Member::currentUser()) {
$fields->add(new RecaptchaField("recapture"));
}
$form = new Form(
$controller = $this,
$name = "Form",
$fields,
$actions = new FieldList(
// List the action buttons here
new FormAction("placeAd", "Place Your Advert")
),
$requiredFields = new RequiredFields(
"Content"
// List the required fields here: "Email", "FirstName"
)
);
$Params = $this->getURLParams();
$URLSegment = Convert::raw2sql($Params['ID']);
if($URLSegment && $advert = Advert::get()->byId($URLSegment))
{
$form->loadDataFrom($advert);
}
return $form;
}
And my placeAd() function has the following code:
public function placeAd($data, $form, $another) {
print_r($another);
print_r($data);
print_r($form);
die();
$form->saveInto($ad = new Advert());
//$ad->Content = $data["Content"];
$ad->write();
if ($curMember = Member::currentUser()){
$curMember->Adverts()->add($ad);
$ad->AdvertiserID = $curMember->ID;
}
if ($data["CategoryID"]) {
$ad->CategoryID = $data["CategoryID"];
$category = Category::get()->byId($data["CategoryID"]);
$category->Adverts()->add($ad);
$category->write();
}
$ad->write();
Session::set('info', 'Thanks for your submission');
return $this->redirectBack();
}
obviously some debug statements in there, but i cant get any Pic information (IDs, Names anything) when the form is submitted.