Welcome Guest, Not a member yet? Register   Sign In
Form Validation still not work
#1

[eluser]tashigiri[/eluser]
Hello all..
Im getting stuck with form validation required.
Im always code with the same code i know, but at this time and only this page, my code doesnt work.
anybody can give me suggestion or idea please..
here my controller :
Code:
function new_design_ads()
    {      
        if($this->input->post('submit'))
        {      
            $found = 0;
            $type_valid = 0;
            $date_valid = 1;
            // Set Rules
            $rules['title']         = "required|xss_clean|addslashes";
            $rules['reference']     = "required|xss_clean|addslashes";
            $rules['job_location']    = "required|xss_clean|addslashes";
            $rules['active_date']    = "required";
            $rules['apply_option']    = "required";
            $rules['sectors']         = "required";
            $rules['orientation']     = "required";
            $rules['experience']     = "required";
            $rules['bundesland']     = "required";
            $rules['job_type']        = "required";            
            // Validate active date
            if($this->input->post('active_date') != 'default')
            {
                $input_time = mktime(0,0,0,$this->input->post('month'),$this->input->post('day'),$this->input->post('year'));
                if($input_time < time())
                {
                    $date_valid = 0;
                }
            }
            // Validate input url
            if($this->input->post('apply_option') != 'default')
            {
                $rules['apply_url']    = "required|prep_url";
            }
            $this->validation->set_rules($rules);

            // Repopulated Input Fields
            $fields['title']         = "title";
            $fields['gender']        = "gender";
            $fields['ads_type']        = "ads_type";
            $fields['reference']     = "reference";
            $fields['active_date']    = "active_date";
            $fields['apply_option']    = "apply_option";
            $fields['apply_url']     = "apply_url";
            $fields['gender']         = "gender";
            $fields['job_type']      = "job_type";
            $fields['day']            = "day";
            $fields['month']        = "month";
            $fields['year']            = "year";
            $fields['package_id']   = "package_id";
            $fields['reduce_type']  = "reduce_type";
            $fields['job_location'] = "Standort";
            $this->validation->set_fields($fields);

            if($this->validation->run() == TRUE)
            {
                $advertisement = array();
                $advertisement['job_title']             = $this->input->post('title');
                $advertisement['gender']                = $this->input->post('gender');
                $advertisement['reference']             = $this->input->post('reference');
                $advertisement['timestamp_start']       = ($this->input->post('active_date') == 'default') ? time() : $input_time;
                $advertisement['timestamp_position']     = ($this->input->post('active_date') == 'default') ? time() : $input_time;
                $advertisement['timestamp_end']         = $advertisement['timestamp_start'] + (((24 * 60 * 60) * 7) * 6);// for calculate aktive adver - added by andrian
                $advertisement['ads_type']              = 'design';
                $advertisement['apply_option']          = $this->input->post('apply_option');
                $advertisement['status']                = 'pending';
                $advertisement['job_location']          = $this->input->post('job_location');

                // if apply_url exist
                if($this->input->post('apply_option') != 'default')
                {
                    $advertisement['apply_url']         = $this->input->post('apply_url');
                }
                if ($this->input->post('package_id'))
                {
                    $advertisement['package_id']        = $this->input->post('package_id');
                }
                if ($this->input->post('reduce_type'))
                {
                   $advertisement['reduce_type']        = $this->input->post('reduce_type');
                }
                redirect(COMPONENTS_VIEWS_FOLDER_NAME.'com_advertising/new_design_ads_step2');                
            }
            else
            {              
                if(!isset($_POST['job_type']) && isset($_POST['normal_submit']))
                {
                    $this->mError[] = $this->lang->line('error_required_job_type');
                }
                if(!$date_valid)
                {
                    $this->mError[] = $this->lang->line('error_not_valid_date');
                }
            }        
        } # END IF CLAUSE SUBMIT      
        $data['initdata'] = IMG_URL;    
        $tmp['template_extra_header'] = "[removed][removed]";
        $tmp['template_extra_header'] .= "[removed][removed]";
        $this->templatelib->initialize($this->_themeSettings());
        $this->templatelib->parse(COMPONENTS_VIEWS_FOLDER_NAME.'com_advertising/new_design_ads', isset($data) ? $data : '');
    }
#2

[eluser]tashigiri[/eluser]
and here my view :
Code:
&lt;?php
    $packagetype    = $this->uri->segment(4);
    $packageId    = $this->uri->segment(5);
    $attributes = array('name' => 'form_new_ads','id' => 'form_new_ads', 'onsubmit' => 'standartAdminJS.submitData();');
    echo form_open(COMPONENTS_CONTROLLER_PATH.'com_advertising/new_design_ads/', $attributes,array('submit'=>'submit'));
     ?&gt;
    &lt;input type="hidden" name="reduce_type" value="&lt;?php echo $packagetype;?&gt;" /&gt;
     &lt;input type="hidden" name="package_id" value="&lt;?php echo $packageId;?&gt;" /&gt;
    <table border="0" cellpadding="0" cellspacing="3">
        &lt;?php //if(count($this->mError) > 0) echo "<tr><td colspan=\"3\">" . GenerateErrorMessages($this->mError) . "<tr></td>"; ?&gt;
        <tr>
            <td>Job Titel :</td>
            <td colspan="2">
                &lt;input type="text" name="title" style="width:270px" class="form_input" value="&lt;?php echo isset($this-&gt;validation->title) ? $this->validation->title : '' ?&gt;" />
            </td>
        </tr>
        <tr>
            <td>Referenznummer :</td>
            <td colspan="2">
                &lt;input type="text" name="reference" style="width:100px;" class="form_input" value="&lt;?php echo isset($this-&gt;validation->reference) ? $this->validation->reference : ''?&gt;"/>
            </td>
        </tr>
        <tr>
            <td>Standort :</td>
            <td colspan="2">
                &lt;input type="text" name="job_location" style="width:270px" class="form_input" value="&lt;?php echo isset($this-&gt;validation->job_location) ? $this->validation->job_location : '' ?&gt;" />
            </td>
        </tr>
        <tr>
            <td>Datum Aktivierung :</td>
            <td>
                &lt;input type="radio" value="default" name="active_date" &lt;?php echo (isset($this-&gt;validation->active_date) && $this->validation->active_date == "default") || !(isset($this->validation->active_date)) ? 'checked' : '';?&gt;/> ab sofort
            </td>
            <td>
                &lt;input type="radio" value="custom" name="active_date" &lt;?php echo (isset($this-&gt;validation->active_date) && $this->validation->active_date == "custom") ? 'checked' : '';?&gt;/> oder zuk&uuml;nftiges Datum
                &lt;?php
            
                $day     = array();
                $month     = array();
                $year     = array();
                
                $day[]     = "Tag";
                $month[]= "Monat";
                $year[] = "Jahr";
                for ($i = 1; $i <= 31; $i++)
                {
                    if($i < 10)
                       $i = "0".$i;
                   $day[$i] = $i;
                }
                for($i = 1; $i <=12; $i++)
                {
                    if($i < 10)
                       $i = "0".$i;
                   $month[$i] = $i;
                }
                
                for($i = date('Y'); $i <= date('Y')+100; $i++)
                {
                    $year[$i] = $i;
                }
                            
                echo form_dropdown('day', $day,isset($this->validation->day) ? $this->validation->day : '','class="form_dropdown"');
                echo "&nbsp;";
                echo form_dropdown('month', $month, isset($this->validation->month) ? $this->validation->month : '','class="form_dropdown"');
                echo "&nbsp;";
                echo form_dropdown('year', $year, isset($this->validation->year) ? $this->validation->year : '','class="form_dropdown"');
               ?&gt;
            </td>
        </tr>
        <tr>
            <td>Bewerbungen : </td>
            <td>&lt;input type="radio" value="default" name="apply_option" &lt;?php echo (isset($this-&gt;validation->apply_option) && $this->validation->apply_option == "default") || !(isset($this->validation->apply_option)) ? 'checked' : '';?&gt;/>
            &uuml;ber Jobwiwi Plattform        
            </td>
            <td>
                &lt;input type="radio" value="custom" name="apply_option" &lt;?php echo (isset($this-&gt;validation->apply_option) && $this->validation->apply_option == "custom") ? 'checked' : '';?&gt;/>eigene Plattform
                &lt;input type="text"  name="apply_url" class="form_input" value="&lt;?php echo isset($this-&gt;validation->apply_url) ? $this->validation->apply_url : '';?&gt;"/>
            </td>
        </tr>
        <tr>
            <td colspan="3" align="center">
                <br/>
                &lt;?php //echo form_submit('quick_submit','Kategorisierung durch Jobwiwi durchf&uuml;hren lassen','class="form_button"');    ?&gt;
            </td>
        </tr>
    </table>    
      <div align="center">
          &lt;?php echo form_submit('submit','Weiter','class="form_button"');    ?&gt;
      </div>              
    &lt;?php form_close();?&gt;                
</div>
[removed]
    standartAdminJS.initData("&lt;?php echo $initdata;?&gt;");
    
[removed]

The proble is when in controller, my code just like cant run "rules"..
so if in the view not fill anything, it still can be submitted, and in the controller always run false..
anyone have idea about this??
Thanks
#3

[eluser]Maglok[/eluser]
And what does not work? What is the error?

EDIT: Have you loaded the form validation class?
#4

[eluser]tashigiri[/eluser]
the form when submitted, its direct again to itself..

though i had given rules in my controller that the fields must filled in first, but in the view still not any warning if there are blank fields.

and my code
Code:
if ($this->validation->run() == TRUE)
always get FALSE result, thats why my page cant go anywhere..
do you know the problem is?

Thanks
#5

[eluser]Maglok[/eluser]
"The run() function only returns TRUE if it has successfully applied your rules without any of them failing."

Did you use all the set rules in the form/view? I don't think I see them all.
#6

[eluser]tashigiri[/eluser]
yup i know that..

i think the problem is in "rules", thought i had given "required", it still can be submitted with blank fields.
Do u know why?

Thanks
#7

[eluser]Maglok[/eluser]
The idea is that if you submit it, it will check it. If the validation does not work out, it returns you to the form. If it does, it goes to the success page?
#8

[eluser]tashigiri[/eluser]
yes..
if the validation wrong, it will return false.
If right will go to other page..
do you see any wrong in my code?
#9

[eluser]Maglok[/eluser]
Well your set_rules set all kinds of values you don't actually use, but you do put them on required. Like 'bundesland', I can't seem to find that word anywhere else in the code.

Then you repopulate fields that you don't have a rule for.




Theme © iAndrew 2016 - Forum software by © MyBB