public function action_submit() { // check CSRF token $token = new Token(); if (!$token->validate('attribute_form_' . $this->bID, $this->post('_token'))) { throw new \Exception('Invalid token'); } // get objects $aftID = $this->post('aftID'); $aft = AttributeFormType::getByID($aftID); // create new form entry $af = AttributeForm::add(['aftID' => $aftID]); // get all attributes of type and save values from form to the database $attributes = $aft->getAttributeObjects(); foreach ($attributes as $akID => $ak) { $af->setAttribute($ak, false); } // check SPAM $submittedData = $af->getAttributeDataString(); $antispam = Core::make('helper/validation/antispam'); if (!$antispam->check($submittedData, 'attribute_form')) { if ($aft->getDeleteSpam()) { $af->delete(); } else { $af->markAsSpam(); } } }
public function detail($afID) { $af = AttributeForm::getByID($afID); $aft = AttributeFormType::getByID($af->getTypeID()); $attributes = $aft->getAttributeObjects(); $this->set('af', $af); $this->set('afID', $afID); $this->set('attributes', $attributes); }
public function save($aftID = 0) { $formName = $this->post('formName'); $deleteSpam = $this->post('deleteSpam', 0); $data = ['formName' => $formName, 'deleteSpam' => $deleteSpam]; if ($aftID > 0) { $attributeFormType = AttributeFormType::getByID($aftID); $attributeFormType->update($data); } else { $attributeFormType = AttributeFormType::add($data); $aftID = $attributeFormType->getID(); } // set attributes $attributeFormType->setAttributes($this->post('attributes')); $this->redirect('/dashboard/forms/types/updated'); }
public function filterByType(AttributeFormType $aft) { $this->filterByTypeID($aft->getID()); }
public function getAttributeDataString() { $ret = ''; $aft = AttributeFormType::getByID($this->getTypeID()); $attributes = $aft->getAttributeObjects(); foreach ($attributes as $attribute) { $ret .= sprintf('%s: %s', $attribute->getAttributeKeyDisplayName(), $this->getAttribute($attribute, 'display')); } return $ret; }