Created
October 31, 2012 17:51
-
-
Save Koala/3988648 to your computer and use it in GitHub Desktop.
Redaxo::rex_form NULL-werte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Speichert das Formular. | |
* | |
* Übernimmt die Werte aus den FormElementen in die Datenbank. | |
* | |
* Gibt true zurück wenn alles ok war, false bei einem allgemeinen Fehler, | |
* einen String mit einer Fehlermeldung oder den von der Datenbank gelieferten ErrorCode. | |
*/ | |
/*protected*/ function save() | |
{ | |
$sql = rex_sql::factory(); | |
$sql->debugsql =& $this->debug; | |
$sql->setTable($this->tableName); | |
foreach($this->getSaveElements() as $fieldsetName => $fieldsetElements) | |
{ | |
foreach($fieldsetElements as $element) | |
{ | |
// read-only-fields nicht speichern | |
if(strpos($element->getAttribute('class'), 'rex-form-read') !== false) | |
{ | |
continue; | |
} | |
$fieldName = $element->getFieldName(); | |
$fieldValue = $element->getSaveValue(); | |
// Callback, um die Values vor dem Speichern noch beeinflussen zu können | |
$fieldValue = $this->preSave($fieldsetName, $fieldName, $fieldValue, $sql); | |
// Den POST-Wert in die DB speichern (inkl. slashes ?) | |
if ($fieldValue === NULL) | |
{ | |
$sql->setValue($fieldName, NULL); | |
} | |
else | |
{ | |
$sql->setValue($fieldName, addslashes($fieldValue)); | |
} | |
} | |
} | |
if($this->isEditMode()) | |
{ | |
$sql->setWhere($this->whereCondition); | |
$saved = $sql->update(); | |
} | |
else | |
{ | |
$saved = $sql->insert(); | |
} | |
// ----- EXTENSION POINT | |
if ($saved) | |
$saved = rex_register_extension_point('REX_FORM_SAVED', $saved, array('form' => $this, 'sql' => $sql)); | |
else | |
$saved = $sql->getErrno(); | |
return $saved; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// class rex_form_element | |
var $defaultSaveValue = ''; | |
/** | |
* Default Save Value | |
* @param $value | |
*/ | |
function setDefaultSaveValue($value = '') | |
{ | |
$this->defaultSaveValue = $value; | |
} | |
// --------- Attribute setter/getters | |
function getSaveValue() | |
{ | |
// PHP >= 5.3 only! | |
// return $this->getValue() ?: $this->defaultSaveValue; | |
// für PHP < 5.3 | |
$value = $this->getValue(); | |
return $value ? $value : $this->defaultSaveValue; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$field = &$form->addTextField('gtb'); | |
$field->setLabel("GTB"); | |
$field->setDefaultSaveValue(NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment