Skip to content

Commit

Permalink
fix: Translate old field names so they can actually be used
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 committed Mar 25, 2021
1 parent facb90a commit 867076e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 27 deletions.
21 changes: 19 additions & 2 deletions src/Class-CustomForm.php
Expand Up @@ -118,14 +118,31 @@ public function setOptions()
}
}

class CustomForm_info extends CustomFormBase
{
public function setHtml()
{
$this->input_html = $this->getValue();
$this->output_html = '';
}
public function validate(): bool
{
return true;
}
public function getValue(): string
{
return $this->value;
}
}

class CustomForm_check extends CustomFormBase
{
public function setHtml()
{
global $txt;
$true = (!$this->exists && $this->default) || $this->value;
$this->input_html .= sprintf(
'<input type="checkbox" name="%s[$s]"%s>',
$this->input_html = sprintf(
'<input type="checkbox" text="%s[$s]"%s>',
'CustomFormField',
$this->field['id_field'],
$true ? ' checked' : ''
Expand Down
1 change: 1 addition & 0 deletions src/CustomForm.english.php
Expand Up @@ -59,6 +59,7 @@
$txt['customform_type_select'] = 'Select Box';
$txt['customform_type_radio'] = 'Radio Buttons';
$txt['customform_type_check'] = 'Checkbox';
$txt['customform_type_info'] = 'Information';
$txt['customform_max_length'] = 'Maximum Length';
$txt['customform_max_length_desc'] = '(0 for no limit)';
$txt['customform_dimension'] = 'Dimensions';
Expand Down
16 changes: 14 additions & 2 deletions src/CustomForm.php
Expand Up @@ -84,7 +84,19 @@ function CustomForm()
$data = array();
// Get all of data from the db query.
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$row['type2'] = strtr($row['type'], [
'largetextbox' =>'textarea',
'textbox' =>'text',
'checkbox' =>'check',
'selectbox' =>'select',
'float' =>'text',
'int' =>'text',
'radiobox' =>'radio',
'infobox' =>'info'
]);
$data[] = $row;
}

// Free the db request.
$smcFunc['db_free_result']($request);
Expand Down Expand Up @@ -180,9 +192,9 @@ function CustomForm()
foreach ($data as $field)
{
$value = isset($_POST['CustomFormField'][$field['id_field']]) ? $_POST['CustomFormField'][$field['id_field']] : '';
$class_name = 'CustomForm_' . $field['type'];
$class_name = 'CustomForm_' . $field['type2'];
if (!class_exists($class_name))
fatal_error('Param "' . $field['type'] . '" not found for field "' . $field['text'] . '" at ID #' . $field['id_field'] . '.', false);
fatal_error('Param "' . $field['type2'] . '" not found for field "' . $field['text'] . '" at ID #' . $field['id_field'] . '.', false);

$type = new $class_name($field, $value, !empty($value));
$type->setOptions();
Expand Down
49 changes: 26 additions & 23 deletions src/ManageCustomForm.php
Expand Up @@ -493,7 +493,16 @@ function ModifyCustomFormSettings($return_config = false)
array(
'select',
'field_type',
'value' => $data['type'],
'value' => strtr($data['type'], [
'largetextbox' =>'textarea',
'textbox' =>'text',
'checkbox' =>'check',
'selectbox' =>'select',
'float' =>'text',
'int' =>'text',
'radiobox' =>'radio',
'infobox' =>'info'
]),
'text_label' => $txt['customform_type'],
'help' => 'customform_type',
$result
Expand Down Expand Up @@ -708,7 +717,7 @@ function list_CustomForms()
// Fucntion to produce a list of custom form fields.
function list_customform_fields($nul0, $nul1, $nul2, $id)
{
global $txt, $scripturl, $smcFunc;
global $txt, $scripturl, $sourcedir, $smcFunc;

// Get the data from the cf_fields table.
$request = $smcFunc['db_query'](
Expand All @@ -732,32 +741,26 @@ function list_customform_fields($nul0, $nul1, $nul2, $id)
$i = 1;
$end = count($data);

// Go through every field.
require_once($sourcedir . '/Class-CustomForm.php');
$result = [];
foreach (customform_list_classes() as $cn)
$result[$cn] = $txt['customform_type_' . $cn];
$result += [
'largetextbox' =>$result['textarea'],
'textbox' =>$result['text'],
'checkbox' =>$result['check'],
'selectbox' =>$result['select'],
'float' =>$result['text'],
'int' =>$result['text'],
'radiobox' =>$result['radio'],
'infobox' =>$result['info']
];
foreach ($data as $field)
{
// Convert the field type into the proper text strings.
$type = str_replace(
// Search array.
array('largetextbox', 'textbox', 'checkbox', 'selectbox', 'float', 'int', 'radiobox', 'infobox'),
// Replace array.
array(
$txt['customform_large_textbox'],
$txt['customform_textbox'],
$txt['customform_checkbox'],
$txt['customform_selectionbox'],
$txt['customform_float'],
$txt['customform_int'],
$txt['customform_radiobox'],
$txt['customform_infoboxa'],
),
$field['type']
);

// Add the current entry into the list.
$list[] = array(
'title' => $field['title'],
'text' => $field['text'],
'type' => $type,
'type' => $result[$field['type']]??$field['type'],
'modify' => '
<table width="100%">
<tr>
Expand Down

0 comments on commit 867076e

Please sign in to comment.