Issue with the radio buttons
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 18 Dec 2014 20:05:45 +0000 (15:05 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 18 Dec 2014 20:05:45 +0000 (15:05 -0500)
Fix issue with the radio buttons not being checked if they are set as
required.

controllers/front.php
views/front/formTemplate.php

index 3307d4e..622fa68 100644 (file)
@@ -319,6 +319,7 @@ class glm_employment_front
     public function form_process($part)
     {
         $this->clean_post();
+
         $form = $this->load_form_settings($part);
         if ($jobId = filter_var($_REQUEST['job'], FILTER_VALIDATE_INT)) {
             $this->job = $jobId;
@@ -336,14 +337,17 @@ class glm_employment_front
                 if (in_array($field['name'], array('fname', 'lname', 'mname'))) {
                     $this->$field['name'] = $form[$rowKey][$fieldKey]['value'];
                 }
-                if (   $field['type'] == 'checkbox'
-                    && isset($field['opts'])
-                    && !empty($field['opts'])
+                if (   ($field['type'] == 'checkbox' || $field['type'] == 'radio')
+                    && isset($field['opts']) && !empty($field['opts'])
                 ) {
+
                     foreach ($field['opts'] as $opKey => $option) {
-                        if (isset($_POST[$option['name']])) {
+                        if (isset($_POST[$field['name']])) {
                             $form[$rowKey][$fieldKey]['opts'][$opKey]['checked'] = true;
-                            $_POST[$option['name']] = $option['value'];
+                            if ($field['type'] == 'checkbox') {
+                                $_POST[$option['name']] = $option['value'];
+                            }
+
                         }
                     }
                 }
@@ -351,7 +355,6 @@ class glm_employment_front
                     && $field['req'] == true
                     && $_POST[$field['name']] == ''
                     && (isset($field['type']))
-                    && $field['type'] != 'radio'
                 ) {
                     $form[$rowKey][$fieldKey]['error'] = $field['label'] . ' is required!';
                     ++$this->errorCount;
index 80452a4..9c2bee1 100644 (file)
                                 <?php foreach($field['opts'] as $option) :?>
                                     <input
                                         <?php if (isset($field['error']) && $field['error']){echo 'class="error"';}?>
-                                        <?php if (isset($field['req']) && $field['req']){echo 'required';}?>
+                                        <?php //if (isset($field['req']) && $field['req']){ echo 'required';}?>
                                         <?php if (isset($field['pat']) && $field['pat']):?>
                                         pattern="<?php echo $field['pat'];?>"
                                         <?php endif;?>
                                         id="<?php echo $option['name'];?>"
                                         name="<?php echo $field['name'];?>"
                                         type="radio"
-                                        value="<?php if (isset($field['value'])) { echo $option['value'];}?>"
-                                        <?php if (isset($field['value']) && $field['value'] === $option['value']) {
+                                        value="<?php if (isset($option['value'])) { echo $option['value'];}?>"
+                                        <?php
+                                        $radioOptionValue = filter_var($field['value'], FILTER_VALIDATE_INT);
+                                        if (isset($field['value']) && $radioOptionValue === $option['value']) {
                                             echo 'checked';
                                         }?> />
                                     <label for="<?php echo $option['name'];?>"><?php echo $option['label'];?></label>