Fix fubscription form failing when some fields are absent or don't exist [MAILPOET-764]

This commit is contained in:
Alexey Stoletniy
2017-01-24 21:12:56 +03:00
parent 9a3c4ff7de
commit bfdc13a8d1
5 changed files with 218 additions and 2 deletions

View File

@ -39,6 +39,32 @@ class Form extends Model {
return parent::save();
}
function getFieldList() {
$form = $this->asArray();
if(empty($form['body'])) {
return false;
}
$skipped_types = array('html', 'divider', 'submit');
$fields = array();
foreach((array)$form['body'] as $field) {
if(empty($field['id'])
|| empty($field['type'])
|| in_array($field['type'], $skipped_types)
) {
continue;
}
if($field['id'] > 0) {
$fields[] = 'cf_' . $field['id'];
} else {
$fields[] = $field['id'];
}
}
return $fields ?: false;
}
static function search($orm, $search = '') {
return $orm->whereLike('name', '%'.$search.'%');
}