• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem using model method inside an if statement

#1
[eluser]porta_ss[/eluser]
I need to use a model (called "insertor"). When I call it inside
Code:
if($this->form_validation->run() !== FALSE){}
...it just doesn't work. But if I replace
Code:
if($this->form_validation->run() !== FALSE){}
with
Code:
if(1>0){}
...or anything else...it works :roll: I can't get it right...what's wrong with this line...
Code:
if($this->form_validation->run() !== FALSE){}
????? I have another project too and in that one everything works properly...I spent some time comparing and comparing...nothing seems to be different...but one works...the other doesn't. Form_validation actually works, cause i can see errors being displayed when form is incomplete. but I just can't access the model from within that strange if() statement. Please help me out...

Code:
<?php
class Parser extends Controller{
  function Parser()
  {
    parent::Controller();
    $this->load->helper (array('form','url'));
    $this->load->library('form_validation');
    $this->load->model('insertor');
  }

  function nou()
  {
    //Rules
    $this->form_validation->set_rules('nume', 'Nume', 'required|min_length[2]');
     $this->form_validation->set_rules('prenume', 'Prenume', 'required');
    $this->form_validation->set_rules('oras', 'Oras', 'required');
     $this->form_validation->set_rules('email', 'Email','required|valid_email');
     $this->form_validation->set_rules('telefon', 'Telefon', 'required');
      $this->form_validation->set_rules('referrer', 'Referrer', 'required');

    //Post form data
    $nume = $this->input->post('nume');
    $prenume = $this->input->post('prenume');
    $oras = $this->input->post('oras');
    $email = $this->input->post('email');
    $telefon = $this->input->post('telefon');
    $cui = $this->input->post('cui');
    $referrer = $this->input->post('referrer');
    $ocupatia = $this->input->post('ocupatia');
    $varsta = $this->input->post('varsta');
    $adresa = $this->input->post('adresa');
    $timp = $this->input->post('timp');
    $mesaj = $this->input->post('mesaj');

    //IF FORM IS FINE
    if($this->form_validation->run() !== FALSE)
    {
      $this->insertor->new_reseller($nume,$prenume,$oras,$email,$telefon,$cui,$referrer,$ocupatia,$varsta,$adresa,$timp,$mesaj);      
    }

    //IF FORM IS INCOMPLETE
    else
    {
      $a['uri'] = 'reselleri_webdesign';
      $this->load->view('body/reselleri_view',$a);  
    }
  }
}
?>

#2
[eluser]kurucu[/eluser]
It doesn't explicitly return FALSE, I believe, so you need to change the !== to !=.

#3
[eluser]porta_ss[/eluser]
It won't work. Whatever I place inside that if()...works...but when I put if($this->form_validation->run() !== FALSE) or...like you said...if($this->form_validation->run() != FALSE)...it just stops working. It's weird cause this,for example..works fine:
Code:
if($this->form_validation->run() == FALSE){...}
. Then, if I try this, only the "if()" will execute, but the "else" won't.
Code:
if($this->form_validation->run() == FALSE)
{
    $a['uri'] = 'reselleri_webdesign';
    $this->load->view('body/reselleri_view');
}
else
{
    $this->insertor->new_reseller($nume,$prenume,$oras,$email,$telefon,$cui,$referrer,$ocupatia,$varsta,$adresa,$timp,$mesaj);
}
I just don't know what to do anymore...and this should be such a basic thing to do...

#4
[eluser]BrianDHall[/eluser]
Assign $this->form_validation->run() to a variable, then run var_dump() on it and see just what its returning for you. Then you will know what you need to test for in your loop. If it returns boolean false, then you just need $result == FALSE or just if($result) - I suspect something is going wrong in your form and all it ever does is return FALSE, but you'll need to assign it to a variable and check it to be sure.

#5
[eluser]porta_ss[/eluser]
it returns bool(false) even when it shouldn't Sad . I checked the names of the inputs, then the corresponding names in the controller...they are identical...no typing errors...I don't know...this is the form in the view...
Code:
<?php $this->load->view('general/upper'); $var = base_url() . 'system/application/assets/'; ?>
                <p class="description">Vrei sa fii reseller WebCouture? Completeaza formularul de mai jos si te vom contacta in cel mai scurt timp.</p>
                <p>                
                <div>
                <div style="float:left;width:250px;">
                &lt;?php echo form_open('parser/nou');?&gt;
                
                &lt;?php if(form_error('nume')){echo '<span style="color:red;">' . form_error('nume') . '</span>';} else echo '<label for="nume">Nume</label><br />'; ?&gt;
                &lt;input type="text" name="nume" class="border" /&gt; <span style="color:#ff0000;">*</span><br />
                
                &lt;?php if(form_error('prenume')){echo '<span style="color:red;">' . form_error('prenume') . '</span>';} else echo '<label for="prenume">Prenume</label><br />'; ?&gt;
                &lt;input type="text" name="prenume" class="border" /&gt; <span style="color:#ff0000;">*</span><br />
                
                &lt;?php if(form_error('oras')){echo '<span style="color:red;">' . form_error('oras') . '</span>';} else echo '<label for="oras">Oras</label><br />'; ?&gt;
                &lt;input type="text" name="oras" class="border" /&gt; <span style="color:#ff0000;">*</span><br />
                
                &lt;?php if(form_error('email')){echo '<span style="color:red;">' . form_error('email') . '</span>';} else echo '<label for="email">Email</label><br />'; ?&gt;
                &lt;input type="text" name="email" class="border" /&gt; <span style="color:#ff0000;">*</span><br />
                
                &lt;?php if(form_error('telefon')){echo '<span style="color:red;">' . form_error('telefon') . '</span>';} else echo '<label for="telefon">Telefon</label><br />'; ?&gt;
                &lt;input type="text" name="telefon" class="border" /&gt; <span style="color:#ff0000;">*</span><br />
                
                <label for="cui">C.U.I.</label><br />
                &lt;input type="text" name="cui" class="border" /&gt;&lt;br />
                
                <label for="referrer">Unde ai auzit de WebCouture?</label><br />
                &lt;input type="text" name="referrer" class="border" /&gt;&lt;br />
                </div>
                <div style="float:left;">
                <label for="ocupatia">Ocupatia</label><br />
                &lt;?php if(form_error('ocupatia')){echo form_error('ocupatia');} ?&gt;
                &lt;input type="text" name="ocupatia" class="border" /&gt; <span style="color:#ff0000;">*</span><br />
                
                <label for="varsta">Varsta</label><br />
                &lt;input type="text" name="varsta" class="border" /&gt;&lt;br />
                
                <label for="adresa">Adresa</label><br />
                &lt;input type="text" name="adresa" class="border" /&gt;&lt;br />
                
                <label for="timp">Timp disponibil pentru activitatea de reseller</label><br />
                &lt;input type="text" name="timp" class="border" /&gt;&lt;br />
                
                <label for="mesaj">Mesaj aditional (optional)</label><br />
                &lt;textarea name="mesaj" class="border" cols="40" rows="5"&gt;&lt;/textarea><br /><br />
                &lt;input type="submit" value="Trimite" /&gt;
                &lt;/form&gt;        
                </div></div>
                </p>
            </div>
                    
        </div>    
        
        &lt;?php $this->load->view('general/right'); ?&gt;
        &lt;?php $this->load->view('general/footer'); ?&gt;

#6
[eluser]porta_ss[/eluser]
Solved it...thanks...there was sth. wrong with the rules..."referrer" wasn't supposed to be there...

#7
[eluser]kurucu[/eluser]
Great - I was just thinking it must be your rules lol.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.