/** * Return the html for a field option such as a * dropdown field or a radio check box field * * @return bool|html */ public function addoptionfield() { // passed via the ajax $parent = isset($_REQUEST['Parent']) ? $_REQUEST['Parent'] : false; // work out the sort by getting the sort of the last field in the form +1 if ($parent) { $sql_parent = Convert::raw2sql($parent); $highestSort = DB::query("SELECT MAX(\"Sort\") FROM \"EditableOption\" WHERE \"ParentID\" = '{$sql_parent}'"); $sort = $highestSort->value() + 1; if ($parent) { $object = new EditableOption(); $object->write(); $object->ParentID = $parent; $object->Sort = $sort; $object->Name = 'option' . $object->ID; $object->write(); return $object->EditSegment(); } } return false; }
/** * Return the html for a field option such as a * dropdown field or a radio check box field * * @return bool|html */ public function addoptionfield() { if (!SecurityToken::inst()->checkRequest($this->request)) { return $this->httpError(400); } // passed via the ajax $parent = isset($_REQUEST['Parent']) ? $_REQUEST['Parent'] : false; // work out the sort by getting the sort of the last field in the form +1 if ($parent) { $sql_parent = (int) $parent; $sqlQuery = new SQLQuery(); $sqlQuery = $sqlQuery->setSelect("MAX(\"Sort\")")->setFrom("\"EditableOption\"")->setWhere("\"ParentID\" = {$sql_parent}"); $sort = $sqlQuery->execute()->value() + 1; if ($parent) { $object = new EditableOption(); $object->write(); $object->ParentID = $parent; $object->Sort = $sort; $object->Name = 'option' . $object->ID; $object->write(); return $object->EditSegment(); } } return false; }