Problem using model method inside an if statement - El Forum - 09-21-2009
[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 ...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);
}
}
}
?>
Problem using model method inside an if statement - El Forum - 09-21-2009
[eluser]kurucu[/eluser]
It doesn't explicitly return FALSE, I believe, so you need to change the !== to !=.
Problem using model method inside an if statement - El Forum - 09-21-2009
[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...
Problem using model method inside an if statement - El Forum - 09-21-2009
[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.
Problem using model method inside an if statement - El Forum - 09-21-2009
[eluser]porta_ss[/eluser]
it returns bool(false) even when it shouldn't . 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;">
<?php echo form_open('parser/nou');?>
<?php if(form_error('nume')){echo '<span style="color:red;">' . form_error('nume') . '</span>';} else echo '<label for="nume">Nume</label><br />'; ?>
<input type="text" name="nume" class="border" /> <span style="color:#ff0000;">*</span><br />
<?php if(form_error('prenume')){echo '<span style="color:red;">' . form_error('prenume') . '</span>';} else echo '<label for="prenume">Prenume</label><br />'; ?>
<input type="text" name="prenume" class="border" /> <span style="color:#ff0000;">*</span><br />
<?php if(form_error('oras')){echo '<span style="color:red;">' . form_error('oras') . '</span>';} else echo '<label for="oras">Oras</label><br />'; ?>
<input type="text" name="oras" class="border" /> <span style="color:#ff0000;">*</span><br />
<?php if(form_error('email')){echo '<span style="color:red;">' . form_error('email') . '</span>';} else echo '<label for="email">Email</label><br />'; ?>
<input type="text" name="email" class="border" /> <span style="color:#ff0000;">*</span><br />
<?php if(form_error('telefon')){echo '<span style="color:red;">' . form_error('telefon') . '</span>';} else echo '<label for="telefon">Telefon</label><br />'; ?>
<input type="text" name="telefon" class="border" /> <span style="color:#ff0000;">*</span><br />
<label for="cui">C.U.I.</label><br />
<input type="text" name="cui" class="border" /><br />
<label for="referrer">Unde ai auzit de WebCouture?</label><br />
<input type="text" name="referrer" class="border" /><br />
</div>
<div style="float:left;">
<label for="ocupatia">Ocupatia</label><br />
<?php if(form_error('ocupatia')){echo form_error('ocupatia');} ?>
<input type="text" name="ocupatia" class="border" /> <span style="color:#ff0000;">*</span><br />
<label for="varsta">Varsta</label><br />
<input type="text" name="varsta" class="border" /><br />
<label for="adresa">Adresa</label><br />
<input type="text" name="adresa" class="border" /><br />
<label for="timp">Timp disponibil pentru activitatea de reseller</label><br />
<input type="text" name="timp" class="border" /><br />
<label for="mesaj">Mesaj aditional (optional)</label><br />
<textarea name="mesaj" class="border" cols="40" rows="5"></textarea><br /><br />
<input type="submit" value="Trimite" />
</form>
</div></div>
</p>
</div>
</div>
<?php $this->load->view('general/right'); ?>
<?php $this->load->view('general/footer'); ?>
Problem using model method inside an if statement - El Forum - 09-21-2009
[eluser]porta_ss[/eluser]
Solved it...thanks...there was sth. wrong with the rules..."referrer" wasn't supposed to be there...
Problem using model method inside an if statement - El Forum - 09-21-2009
[eluser]kurucu[/eluser]
Great - I was just thinking it must be your rules lol.
|