Welcome Guest, Not a member yet? Register   Sign In
Form radio buttons will not validate, need help.
#1

[eluser]Judgestar[/eluser]
Hi, I am new to codeigniter and php coding in general. I have been trying to get a questionnaire app I am working on to validate radio button selections. I make sure no radio options are selected and hit submit and it just goes to the next page. I do not get any errors or messages telling me 'hey that shouldn't have worked'.

Here is my form code:

Code:
<?php echo form_open('factors_survey/questions/question2');
  
  $factor5 = array(
   'name'   =>   'factor1',
   'id'     =>   'factor5',
   'value'  =>   '5'
  );

  $factor4 = array(
   'name'   =>   'factor1',
   'id'     =>   'factor4',
   'value'  =>   '4'
  );

  $factor3 = array(
   'name'   =>   'factor1',
   'id'     =>   'factor3',
   'value'  =>   '3'
  );

  $factor2 = array(
   'name'   =>   'factor1',
   'id'     =>   'factor2',
   'value'  =>   '2'
  );

  $factor1 = array(
   'name'   =>   'factor1',
   'id'     =>   'factor1',
   'value'  =>   '1'
  );

?>
  <tr>
   <td>
    <table class="Questions" cellspacing="0" width"100%">
     <tbody>
      <tr class="FactorTableHeader">
       <td width="30%">
        <td id="ChoiceFiveHeader" valign="top" class="AnswerText" width="75">Very Important</td>
        <td id="ChoiceFourHeader" valign="top" class="AnswerText" width="75">/td>
        <td id="ChoiceThreeHeader" valign="top" class="AnswerText" width="75">Somewhat Important</td>
        <td id="ChoiceTwoHeader" valign="top" class="AnswerText" width="75">/td>
        <td id="ChoiceOneHeader" valign="top" class="AnswerText" width="75">Not Important</td>
       </td>
      </tr>
       <tr class="FactorOne">
        <td>An interesting job:</td>
        <td valign="top" align="center" class="AnswerRadio" width="75">&lt;?php echo form_radio($factor5); ?&gt;</td>&lt;?php echo form_error('factor5'); ?&gt;
        <td valign="top" align="center" class="AnswerRadio" width="75">&lt;?php echo form_radio($factor4); ?&gt;</td>&lt;?php echo form_error('factor4'); ?&gt;
        <td valign="top" align="center" class="AnswerRadio" width="75">&lt;?php echo form_radio($factor3); ?&gt;</td>&lt;?php echo form_error('factor3'); ?&gt;
        <td valign="top" align="center" class="AnswerRadio" width="75">&lt;?php echo form_radio($factor2); ?&gt;</td>&lt;?php echo form_error('factor2'); ?&gt;
        <td valign="top" align="center" class="AnswerRadio" width="75">&lt;?php echo form_radio($factor1); ?&gt;</td>&lt;?php echo form_error('factor1'); ?&gt;
       </tr>
       <tr class="FactorScale">
        <td width="30%">
         <td valign="top" align="center" class="AnswerText" width="75">5</td>
         <td valign="top" align="center" class="AnswerText" width="75">4</td>
         <td valign="top" align="center" class="AnswerText" width="75">3</td>
         <td valign="top" align="center" class="AnswerText" width="75">2</td>
         <td valign="top" align="center" class="AnswerText" width="75">1</td>
        </td>
       </tr>
       <tr class="FactorSubmit">
        <td width="30%">
         <td valign="top" align="center" class="AnswerText" width="75"></td>
         <td valign="top" align="center" class="AnswerText" width="75"></td>
         <td valign="top" align="center" class="AnswerText" width="75">&lt;?php echo form_submit('submit', 'Next Factor'); ?&gt;</td>
         <td valign="top" align="center" class="AnswerText" width="75"></td>
         <td valign="top" align="center" class="AnswerText" width="75"></td>
        </td>
       </tr>
     </tbody>
    </table>
   </td>
  </tr>
&lt;?php echo form_close(); ?&gt;


and here is my controller code:

Code:
public function FactorQuestions()
{
  $this->load->library('form_validation');

  $this->form_validation->set_error_delimiters('', '<br>');
  $this->form_validation->set_rules('factor1', 'Factor One Selection', 'trim|required|xss_clean');

  if ($this->form_validation->run() === FALSE)
  {
   $data['title'] = "Factors Questionnaire";
   $this->load->view('factors_survey/questions_view', $data);  
  }
  else
  {
   $factor1 = $this->input->post('factor1');
                        
                        //sends radio value to database, work in progress
                        //$factor1score = $this->User_Model->update_factor_score($factor1);

   if (!isset($factor1score))
   {
    //error message
   }
   else
   {
    $survey_data = array('Factor1score' => $factor1);
    $this->session->set_userdata($survey_data);
    redirect('factors_survey/questions/question2');
   }
  }
}

I have a login form for the same app before this part that is working perfectly, it takes the name input form, validates it and sends the post data to my database. It remembers the post value and takes the user to the first question and then the validation for the radio form does not work. I have been working on this for a few days now and I have no idea how to fix this, any help and/or assistance is greatly appreciated.


Messages In This Thread
Form radio buttons will not validate, need help. - by El Forum - 05-09-2012, 08:19 AM
Form radio buttons will not validate, need help. - by El Forum - 05-09-2012, 09:41 AM
Form radio buttons will not validate, need help. - by El Forum - 05-09-2012, 10:10 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 09:53 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 10:06 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 10:28 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 10:33 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 10:38 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 10:39 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 10:41 AM
Form radio buttons will not validate, need help. - by El Forum - 05-10-2012, 10:50 AM
Form radio buttons will not validate, need help. - by El Forum - 05-11-2012, 07:14 AM
Form radio buttons will not validate, need help. - by El Forum - 05-11-2012, 09:21 AM
Form radio buttons will not validate, need help. - by El Forum - 05-11-2012, 09:26 AM
Form radio buttons will not validate, need help. - by El Forum - 05-11-2012, 09:30 AM
Form radio buttons will not validate, need help. - by El Forum - 05-11-2012, 09:44 AM
Form radio buttons will not validate, need help. - by El Forum - 05-11-2012, 09:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB