Welcome Guest, Not a member yet? Register   Sign In
Form Validation always returns false!
#1

[eluser]jookoo[/eluser]
I always get into if (!$this->form_validation->run()) and it never gets true, so that the course will be inserted! Do you have an idea?

Thank you!

View:
Quote:<h1>New course</h1>
<div id="body">

&lt;?php echo form_open("course/create"); ?&gt;
<div class = "box">

<label for="title">Bezeichnung:* </label> <br/>
&lt;input type="text" name="title" /&gt;&lt;br /><br/>

<label for="description">Kursbeschreibung*: </label> <br/>
&lt;textarea type="text" name="description" cols="50" rows="10"&gt;&lt;/textarea><br /><br/>

<label for="start_date">Kursbeginn:* </label>
&lt;input type="text" name="start_date" value="&lt;?=date("d.m.Y")?&gt;"/&gt;
&lt;input type="text" name="start_clock" value="&lt;?=date("H:i")?&gt;"/&gt;&lt;br/>

<label for="end_date">Kursende:* </label>
&lt;input type="text" name="end_date" value="&lt;?=date("d.m.Y")?&gt;"/&gt;
&lt;input type="text" name="end_clock" value="&lt;?=date("H:i")?&gt;"/&gt;&lt;br/>

<label for="address">Adresse*: </label>
&lt;input type="text" name="address" /&gt;&lt;br />

<label for="city">Ort*: </label>
&lt;input type="text" name="city" /&gt;&lt;br />

<label for="zip">PLZ*: </label>
&lt;input type="text" name="zip" /&gt;&lt;br />

<label for="group_size_max">Max. Gruppengr&ouml;&szlig;e*: </label>
&lt;input type="text" name="group_size_max" /&gt;&lt;br />
</div>
<div class="box">
<p><b>Informationen zur Zahlung</b></p>
<label for="costs">Kosten (in &euro;, inkl. MwSt.):</label>
&lt;input type="text" name="costs"/&gt;
&lt;input type="checkbox" name="costs_materials" value="true"&gt;inkl. Materialien<br />

<label for = "payment-type">Zahlungsart:</label>
&lt;input type="text" name="payment-type"/&gt;
</div>

<div class="box">
<p><b>Zus&auml;tzliche Informationen</b></p>
&lt;input type="checkbox" name="female" value="true"&gt;nur f&uuml;r Frauen!<br />
&lt;input type="checkbox" name="senior" value="true"&gt;nur f&uuml;r Senioren!<br />
&lt;input type="checkbox" name="junior" value="true"&gt;nur f&uuml;r Kinder!<br />
</div>
<p>&lt;?php echo form_submit('submit', 'Kurs anlegen'); ?&gt;</p>

&lt;?php echo form_close(); ?&gt;
</div>

Controller:
Code:
public function create()
    {
        //check if user is logged in
        //if not, redirect user to login page
        if (!$this->ion_auth->logged_in())
        {
            redirect('auth/login', 'refresh');
        }

        $this->form_validation->set_rules('title', 'Bezeichnung', 'required');
            $this->form_validation->set_rules('description', 'Beschreibung', 'required');
            $this->form_validation->set_rules('start_date', 'Beginn', 'required');
            $this->form_validation->set_rules('end_date', 'Ende', 'required');
            $this->form_validation->set_rules('address', 'Addresse', 'required');
            $this->form_validation->set_rules('city', 'Stadt', 'required');
            $this->form_validation->set_rules('zip', 'PLZ', 'required');
            $this->form_validation->set_rules('costs', 'costs', 'required');
            $this->form_validation->set_rules('payment_type', 'Zahlungsart', 'required');
            $this->form_validation->set_rules('group_size_max', 'Max Gruppengröße', 'required');


        if (!$this->form_validation->run())
        {
            $this->load->view('templates/header');
            $this->load->view('course/create'); //display the form again
            $this->load->view('templates/footer');
        }
        else
        {
            $course_id = $this->course_model->create();
            $this->data['message'] = 'Sie haben erfolgreich Ihren Kurs angelegt.';
            $this->load->view('templates/header');
            $this->load->view('private', $this->data);
            $this->load->view('templates/footer');
        }
#2

[eluser]jprateragg[/eluser]
You have a typo for "payment type." Your validation rule checks for "payment_type" (underscore), but your html field name is "payment-type" (dash). I think that's where your problem is.
#3

[eluser]jookoo[/eluser]
Thank you! It worked!




Theme © iAndrew 2016 - Forum software by © MyBB