Skip to content

Commit

Permalink
44694 remove br tag & refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
yeneastgate committed Jul 9, 2024
1 parent 973a0d9 commit 1e3a4d8
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 39 deletions.
2 changes: 1 addition & 1 deletion css/onoffice-forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ span.onoffice-pleasefill {
pointer-events: none;
}

.oo-form .hidden-field {
.oo-hidden-field {
display: none;
}
1 change: 0 additions & 1 deletion dist/onoffice-hidden-field.min.js

This file was deleted.

11 changes: 0 additions & 11 deletions js/onoffice-hidden-field.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,6 @@ private function renderScriptForFormPage(array $scripts, string $pluginPath, str
$scripts[] = (new IncludeFileModel($script, 'onoffice-prevent-double-form-submission', plugins_url('/dist/onoffice-prevent-double-form-submission.min.js', $pluginPath)))
->setDependencies(['jquery'])
->setLoadInFooter(true);
$scripts[] = (new IncludeFileModel($script, 'onoffice-hidden-field', plugins_url('/dist/onoffice-hidden-field.min.js', $pluginPath)))
->setDependencies(['jquery'])
->setLoadInFooter(true);

if ($this->checkFormType($forms, [Form::TYPE_APPLICANT_SEARCH])) {
$scripts[] = (new IncludeFileModel($script, 'onoffice-form-preview', plugins_url('/dist/onoffice-form-preview.min.js', $pluginPath)))
Expand Down
10 changes: 5 additions & 5 deletions templates.dist/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function renderFormField(string $fieldName, onOffice\WPlugin\Form $pForm, bool $

if (\onOffice\WPlugin\Types\FieldTypes::FIELD_TYPE_SINGLESELECT == $typeCurrentInput) {
$output .= '<select size="1" name="' . esc_html($fieldName) . '" ' . $requiredAttribute;
$output .= $isHiddenField ? 'class="hidden-field" disabled ' : 'class="custom-single-select"';
$output .= $isHiddenField ? 'class="oo-hidden-field" disabled ' : 'class="custom-single-select"';
$output .= '>';
/* translators: %s will be replaced with the translated field name. */
$output .= '<option value="">' . esc_html(sprintf(__('Choose %s', 'onoffice-for-wp-websites'), $fieldLabel)) . '</option>';
Expand Down Expand Up @@ -176,14 +176,14 @@ function renderFormField(string $fieldName, onOffice\WPlugin\Form $pForm, bool $
$htmlOptions .= '<option value="' . esc_attr($key) . '".' . ($isSelected ? ' selected' : '') . '>' . esc_html($value) . '</option>';
}
$output = '<select name="' . esc_html($fieldName) . '[]" multiple="multiple" ' . $requiredAttribute;
$output .= $isHiddenField ? 'class="hidden-field" disabled ' : 'class="custom-multiple-select form-control"' . '>';
$output .= $isHiddenField ? 'class="oo-hidden-field" disabled ' : 'class="custom-multiple-select form-control"' . '>';
$output .= $htmlOptions;
$output .= '</select>';
} else {
$inputType = 'type="text" ';
$value = 'value="' . esc_attr($pForm->getFieldValue($fieldName, true)) . '"';
if ($isHiddenField === true) {
$inputType .= 'class="hidden-field" disabled ';
$inputType .= 'class="oo-hidden-field" disabled ';
} elseif ($typeCurrentInput == onOffice\WPlugin\Types\FieldTypes::FIELD_TYPE_BOOLEAN) {
$inputType = 'type="checkbox" ';
$value = 'value="y" ' . ($pForm->getFieldValue($fieldName, true) == 1 ? 'checked="checked"' : '');
Expand Down Expand Up @@ -219,7 +219,7 @@ function renderFormField(string $fieldName, onOffice\WPlugin\Form $pForm, bool $
. $value . ' placeholder="' . esc_attr($rangeDescription) . '">';
}
} elseif ($typeCurrentInput === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT) {
$additionHidden = $isHiddenField === true ? 'class="hidden-field" disabled ' : '';
$additionHidden = $isHiddenField === true ? 'class="oo-hidden-field" disabled ' : '';
$output = '<fieldset '.$additionHidden.'>
<input type="radio" id="' . esc_attr($fieldName) . '_u" name="' . esc_attr($fieldName) . '" value=""
' . ($selectedValue == '' ? ' checked' : '') . '>
Expand Down Expand Up @@ -253,7 +253,7 @@ function renderRegionalAddition(string $inputName, array $selectedValue, bool $m
}

$output .= '<select name="' . $name . '" ' . $multipleAttr . ' ' . $requiredAttribute ;
$output .= $isHiddenField ? 'class="hidden-field" disabled ' : '';
$output .= $isHiddenField ? 'class="oo-hidden-field" disabled ' : '';
$output .= '>';
$pRegionController = new RegionController();

Expand Down
10 changes: 7 additions & 3 deletions templates.dist/form/applicantform.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

$addressValues = array();
$searchcriteriaValues = array();
$hiddenValues = array();

if ($pForm->getFormStatus() === \onOffice\WPlugin\FormPost::MESSAGE_SUCCESS) {
echo '<p>'.esc_html__('SUCCESS!', 'onoffice-for-wp-websites').'</p>';
Expand All @@ -43,6 +44,10 @@

/* @var $pForm \onOffice\WPlugin\Form */
foreach ( $pForm->getInputFields() as $input => $table ) {
if ($pForm->isHiddenField($input)) {
$hiddenValues []= renderFormField($input, $pForm);
continue;
}
$isRequired = $pForm->isRequiredField( $input );
$addition = $isRequired ? '*' : '';
$isHiddenField = $pForm->isHiddenField($input);
Expand All @@ -55,10 +60,8 @@
}

if ( in_array( $input, array( 'gdprcheckbox' ) ) ) {
$isHiddenField = $pForm->isHiddenField('gdprcheckbox');
$fieldLabel = $pForm->getFieldLabel( 'gdprcheckbox' );
$line = renderFormField( 'gdprcheckbox', $pForm );
$line .= !$isHiddenField ? $fieldLabel : '';
$line .= $pForm->getFieldLabel( 'gdprcheckbox' );
}
if ($table == 'address') {
$addressValues []= $line;
Expand Down Expand Up @@ -88,6 +91,7 @@
<?php echo implode('<br>', $searchcriteriaValues) ?>
</div>
</p>
<?php echo implode($hiddenValues); ?>
<div>
<?php
include(ONOFFICE_PLUGIN_DIR.'/templates.dist/form/formsubmit.php');
Expand Down
14 changes: 6 additions & 8 deletions templates.dist/form/defaultform.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,29 @@
continue;
}
if ( in_array( $input, array( 'gdprcheckbox' ) ) ) {
$isHiddenField = $pForm->isHiddenField('gdprcheckbox');
$fieldLabel = $pForm->getFieldLabel('gdprcheckbox');
echo renderFormField( 'gdprcheckbox', $pForm );
echo !$isHiddenField ? $fieldLabel . '<br>' : '';
echo $pForm->getFieldLabel( 'gdprcheckbox' ) . '<br>';
continue;
}
if ( in_array( $input, array( 'message' ) ) ) {
$isRequiredMessage = $pForm->isRequiredField( 'message' );
$additionMessage = $isRequiredMessage ? '*' : '';
$isHiddenField = $pForm->isHiddenField('message');
$additionHidden = $isHiddenField ? 'class="hidden-field" disabled' : '';
if (!$isHiddenField) {
echo $pForm->getFieldLabel( 'message' );
echo $additionMessage . ':<br>';
echo '<textarea name="message">' . $pForm->getFieldValue('message') . '</textarea><br>';
} else {
echo '<textarea name="message" class="hidden-field" disabled">' . $pForm->getFieldValue('message') . '</textarea>';
}
echo '<textarea name="message" '.$additionHidden.'>' . $pForm->getFieldValue( 'message' ) . '</textarea><br>';
continue;
}

$isRequired = $pForm->isRequiredField( $input );
$addition = $isRequired ? '*' : '';
$isHiddenField = $pForm->isHiddenField($input);
$line = $pForm->getFieldLabel($input).$addition.': ';
echo !$isHiddenField ? $line : '';
echo renderFormField($input, $pForm).'<br>';
$label = $pForm->getFieldLabel($input).$addition.': ';
echo !$isHiddenField ? $label . renderFormField($input, $pForm).'<br>' : renderFormField($input, $pForm);
}
?>

Expand Down
12 changes: 8 additions & 4 deletions templates.dist/form/ownerform.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

$addressValues = array();
$estateValues = array();
$hiddenValues = array();

if ($pForm->getFormStatus() === \onOffice\WPlugin\FormPost::MESSAGE_SUCCESS) {
echo esc_html__('SUCCESS!', 'onoffice-for-wp-websites');
Expand All @@ -43,6 +44,10 @@

/* @var $pForm \onOffice\WPlugin\Form */
foreach ( $pForm->getInputFields() as $input => $table ) {
if ($pForm->isHiddenField($input)) {
$hiddenValues []= renderFormField($input, $pForm);
continue;
}
$isRequired = $pForm->isRequiredField($input);
$addition = $isRequired ? '*' : '';
$isHiddenField = $pForm->isHiddenField($input);
Expand All @@ -54,16 +59,14 @@
$line .= ' <span>'.esc_html__('Please fill in', 'onoffice-for-wp-websites').'</span>';
}
if ( in_array( $input, array( 'gdprcheckbox' ) ) ) {
$isHiddenField = $pForm->isHiddenField('gdprcheckbox');
$fieldLabel = $pForm->getFieldLabel('gdprcheckbox');
$line = renderFormField( 'gdprcheckbox', $pForm );
$line .= !$isHiddenField ? $fieldLabel : '';
$line .= $pForm->getFieldLabel( 'gdprcheckbox' );
}
if ( in_array( $input, array( 'message' )) ) {
$isRequiredMessage = $pForm->isRequiredField( 'message' );
$additionMessage = $isRequiredMessage ? '*' : '';
$isHiddenField = $pForm->isHiddenField('message');
$additionHidden = $isHiddenField ? 'class="hidden-field" disabled' : '';
$additionHidden = $isHiddenField ? 'class="oo-hidden-field" disabled' : '';

$line = $pForm->getFieldLabel('message').$additionMessage.':<br>';
$line = !$isHiddenField ? $line : '';
Expand All @@ -90,6 +93,7 @@
<p>';
echo implode('<br>', $estateValues);
echo '</p>';
echo implode($hiddenValues);

include(ONOFFICE_PLUGIN_DIR.'/templates.dist/form/formsubmit.php');
}
Expand Down
9 changes: 6 additions & 3 deletions templates.dist/form/ownerleadgeneratorform.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
$addressValues = array();
$estateValues = array();
$miscValues = array();
$hiddenValues = array();

if ($pForm->getFormStatus() === FormPost::MESSAGE_SUCCESS) {
esc_html_e('The form was sent successfully.', 'onoffice-for-wp-websites');
Expand All @@ -44,6 +45,10 @@

/* @var $pForm Form */
foreach ( $pForm->getInputFields() as $input => $table ) {
if ($pForm->isHiddenField($input)) {
$hiddenValues []= renderFormField($input, $pForm);
continue;
}
if ( $pForm->isMissingField( $input ) &&
$pForm->getFormStatus() == FormPost::MESSAGE_REQUIRED_FIELDS_MISSING) {
/* translators: %s will be replaced with a translated field name. */
Expand All @@ -52,9 +57,7 @@

$isRequired = $pForm->isRequiredField($input);
$addition = $isRequired ? '*' : '';
$isHiddenField = $pForm->isHiddenField($input);
$line = $pForm->getFieldLabel($input).$addition.': ';
$line = !$isHiddenField ? $line : '';
$line .= renderFormField($input, $pForm);

if ($table == 'address') {
Expand Down Expand Up @@ -112,7 +115,7 @@
</div>
</p>
</div>

<?php echo implode($hiddenValues); ?>
<span class="leadform-back" style="float:left; cursor:pointer;">
<?php echo esc_html__('Back', 'onoffice-for-wp-websites'); ?>
</span>
Expand Down

0 comments on commit 1e3a4d8

Please sign in to comment.