Welcome Guest, Not a member yet? Register   Sign In
Second call to view with a form ignored by CI
#1

[eluser]ZoranM[/eluser]
Hi all,
I am enjoying programming with CI for a few weeks and my first app is getting bigger and more functional every day.

My controller is welcome.php, and my app is with two forms, simply saying cas_formular and cas_kontrola, and I am not using sessions (yet).

First form, opened with
Code:
form_open('welcome/racunaj_cas')
, is for entering many fields: some of them text, some of them date, most of them ammount of money.

When first form is submitted to function racunaj_cas(), racunaj_cas() calculates all the sums and prepare all other variables taking values from other form fields and putting in a $data_cas array.

Then it calls another view
Code:
$this->load->view('cas_kontrola', $data_cas);
with a form, similar to first one, but expanded with calculated sums. There is also a validation of the form, because there are several requested fields. This second form is opened with
Code:
form_open('welcome/upisi_u_bazu');
and has two submit buttons - one for recalculation of the figures and other for saving the data. These two forms are working like a charm and send data to controller, controller send them data for the first time with no problem.

So, the program should run in the loop (I mean function upisi_u_bazu()) as long as there are empty requested fields nevertheless of submitted button. That control works fine, logic performs well:

Code:
if ($this->form_validation->run() == FALSE)
{
    echo '[removed]alert("ALERT: There is at least one empty field which is required, please enter required value(s)");[removed]';
    $this->load->view('cas_kontrola', $data_cas);
    echo "I should call cas_kontrola view, but I did not!";
}

My problem is that, when logic in function upisi_u_bazu() decides to call a view with a second form with refreshed data
Code:
$this->load->view('cas_kontrola', $data_cas);
, CI ignores that call with no error messages and program continues to work further like there was no call to a view (echoes "I should call cas_kontrola view, but I did not!") which is not a desired behavior.

Is it allowed to call repeatedly view
Code:
$this->load->view('cas_kontrola', $data_cas);
from the controller function upisi_u_bazu() that is responsible for the form in that view
Code:
form_open('welcome/upisi_u_bazu');
?

I am obviously missing something here, tried to search in forum with similar problem, googled it with no success.

Please advise what am I doing wrong.
Thanking you in advance,
Best regards,
Zoran
#2

[eluser]InsiteFX[/eluser]
did you use a form_close on the end of your forms?

InsiteFX
#3

[eluser]ZoranM[/eluser]
I used
Code:
</form>
tag. I replaced it after Your qeustion with
Code:
<?php echo form_close(); ?>
with no change in behavior.

Thanks for a try,
Regards,
Zoran
#4

[eluser]kaejiavo[/eluser]
[quote author="ZoranM" date="1288118097"]
Code:
if ($this->form_validation->run() == FALSE)
{
    echo '[removed]alert("ALERT: There is at least one empty field which is required, please enter required value(s)");[removed]';
    $this->load->view('cas_kontrola', $data_cas);
    echo "I should call cas_kontrola view, but I did not!";
}

My problem is that, when logic in function upisi_u_bazu() decides to call a view with a second form with refreshed data
Code:
$this->load->view('cas_kontrola', $data_cas);
, CI ignores that call with no error messages and program continues to work further like there was no call to a view (echoes "I should call cas_kontrola view, but I did not!") which is not a desired behavior.
[/quote]

Hi,
if you put the line with the echo "I Should..." after the load->view line, it will always be executed - Even if your view is perfectly loaded. (I tested it right now)
So, what happens if you leave this away?

Marco
#5

[eluser]ZoranM[/eluser]
I commented out that echo, problem persists. There is same behavior with this part of the program:

Code:
$check = $_POST['pritisnuto'];
        echo "pritisnuto " .  $check;
if ($check == "Check"){
    $this->load->view('cas_kontrola', $data_cas);
    }
where pritisnuto are two submit buttons in the form:

Code:
<div>&lt;input type="submit" name="pritisnuto" value="Check" /&gt;
&lt;input type="submit" name="pritisnuto" value="Done and save" /&gt;&lt;/div>

This call too does not work
Code:
$this->load->view('cas_kontrola', $data_cas);
just passes by to next line.
#6

[eluser]InsiteFX[/eluser]
It could be that you are losing the data between function calls!

Read this:
CodeIgniter User Guide - Flashdata

InsiteFX
#7

[eluser]ZoranM[/eluser]
[quote author="InsiteFX" date="1288123717"]It could be that you are losing the data between function calls!

Read this:
CodeIgniter User Guide - Flashdata

InsiteFX[/quote]

Thanks InsiteFX,

I am not sure if I follow you: data is prepared in function which calls view with a form which then shows sent data. It works well every first call. But with second call no form is displayed.

If data was lost, forms would be shown empty, right? But in my case forms are not shown at all, execution just passes those calls further like these calls don't exist.

Thanks again for a try,
Zoran
#8

[eluser]ZoranM[/eluser]
Few minutes ago, one detail in calling the views came in my sight: in every working part, call of the view as at the end of the function. In these parts with a problem, these calls are under if statement and certainly function does not end with them - that was the real cause of the problem.

So, what I did to try to correct my problem is to make same thing in these function: after call of the view, function will come to an end which was possible thanks to else statement:

Code:
if ($this->form_validation->run() == FALSE)
    {
    echo '[removed]alert("ALERT: There is at least one empty field which is required, please enter required value(s)");[removed]';
    $this->load->view('cas_kontrola', $data_cas);
    }
else
    {
    $check = $_POST['pritisnuto'];
        echo "pritisnuto " .  $check;
    if ($check == "Check"){
        $this->load->view('cas_kontrola', $data_cas);
    }
    else
    {
        echo "Done and save" . $check;
        ....
    } // end of second if
} // end of first if
and closing brackets of the function.

So, it works fine now. Thanks to all who tried to help. Once more it is proven that we, who ask for help, did not do everything by the book Smile))))

Best regards,
Zoran

PS
Dunno how to mark this post as SOLVED.




Theme © iAndrew 2016 - Forum software by © MyBB