Welcome Guest, Not a member yet? Register   Sign In
cannot user redirect() function..
#1

[eluser]scorpioniz[/eluser]
cannot use redirect function after
Code:
$this->form_validation->run

i have function:

Code:
function edit($id = NULL){
  $user_id = 25;
  $event = $this->database->GetSingle('events', array('id' => $id, 'userid' => $user_id));
  $this->data['event'] = $event;
  //redirect('user/event/show/'.$event['id']);
  if($this->form_validation->run('event/createedit') == FALSE){
    $this->ajaxValidation('event/createedit');
  }else{
    if($event == NULL){
      $this->database->Insert('events', $data);
      $event_id = $this -> database -> GetLastID();


    }else{
      $this->database->Update('events', $data, array('id' => $event['id']));
      $event_id = $event['id'];
    }
    redirect('user/event/show/'.$event_id);
  }
}

and if i put redirect before
Code:
if($this->form_validation->run('event/createedit') == FALSE)
statement its redirecting me where i need..

plz help..

also i notice that it tries to redirect where i need, but than it re-redirects to the edit page..
#2

[eluser]Tim Brownlaw[/eluser]
That sounds like it's not "getting" there... So it's not being executed!

What if you temporarily add just prior to the redirect ( or comment out the redirect ) with...

Code:
echo 'Hello - I am at line: '. __LINE__.'<br>';
exit();

You can plonk that echo statement ( without the exit) in your if's and else's to see where the code is going and where it isn't. The exit() just stops the script whizzing along...

I use that all the time to quickly find out what's going on when things go "Strange"!



#3

[eluser]scorpioniz[/eluser]
[quote author="Tim Brownlaw" date="1410581572"]That sounds like it's not "getting" there... So it's not being executed!

What if you temporarily add just prior to the redirect ( or comment out the redirect ) with...

Code:
echo 'Hello - I am at line: '. __LINE__.'<br>';
exit();

You can plonk that echo statement ( without the exit) in your if's and else's to see where the code is going and where it isn't. The exit() just stops the script whizzing along...

I use that all the time to quickly find out what's going on when things go "Strange"!

[/quote]

hm.. i was already trying with exit, and it's working.. .. my DB sql's also are working, but redirect just stops.. :// and i have notice that in chrome developer tools (F12) where is network section i see that it load my view of show.. and i see all the code inside of that link, but second one is again edit, and it loads it
#4

[eluser]Tim Brownlaw[/eluser]
You have...
Code:
if($this->form_validation->run('event/createedit') == FALSE){

From the User Guide: $this->form_validation->run();
Runs the validation routines. Returns boolean TRUE on success and FALSE on failure. You can optionally pass the name of the validation group via the function, as described in: Saving Groups of Validation Rules to a Config File.

So I'm unsure as to what you were intending by passing 'event/createedit' through it... It probably always returns FALSE!





#5

[eluser]scorpioniz[/eluser]
[quote author="Tim Brownlaw" date="1410622090"]You have...
Code:
if($this->form_validation->run('event/createedit') == FALSE){

From the User Guide: $this->form_validation->run();
Runs the validation routines. Returns boolean TRUE on success and FALSE on failure. You can optionally pass the name of the validation group via the function, as described in: Saving Groups of Validation Rules to a Config File.

So I'm unsure as to what you were intending by passing 'event/createedit' through it... It probably always returns FALSE!

[/quote]

If it always would return false, than it never would update or insert my sql's, and like i was saying in previous post it's doing it (update/insert to my DB), so it's not always returning false.

and this funkcion is just for simple add/edit record to/on DB from simple form.
if it's false, then it load's view, else - doing update/insert record to DB
#6

[eluser]Tim Brownlaw[/eluser]
Well I was just curious if you had a validation rule array called event/createedit! Or there's something missing in the userguide I'm not aware of that simply ignores that or....

Anyway I don't have your code in front of me so I don't know if you put in yourdomain.com/user/event/show/1 ( assuming 1 is a valid id) works...

Kind of running out of ideas here Smile
#7

[eluser]scorpioniz[/eluser]
[quote author="Tim Brownlaw" date="1410625216"]Well I was just curious if you had a validation rule array called event/createedit! Or there's something missing in the userguide I'm not aware of that simply ignores that or....

Anyway I don't have your code in front of me so I don't know if you put in yourdomain.com/user/event/show/1 ( assuming 1 is a valid id) works...

Kind of running out of ideas here Smile
[/quote]

that's i'm talking about.. because everywhere else redirect() function working fine.. but just not here.. :/

i am thinking maybe it's not enough time.. simetimes sleep helps.. sad that i do not have here that code, to try (on monday I will, unless i will find another solution).

and about show page.. yes mydomain.com/user/event/show/1 is valid and opens page perfectly if i put my redirect before IF statement.. (actioly i didn't try to run redirect in if before ajaxValidation(); )

if you would see my code in first post there is commented line with redirect, and if I uncomment it and run it - it's redirecting to page perfectly.. :/ but not at the end of else statement.. :///
#8

[eluser]Tim Brownlaw[/eluser]
Well it seems we are all guilty at some stage of not reading everything that is posted!

#9

[eluser]InsiteFX[/eluser]
Shouldn't you be using this to check and make sure you are getting an ajax request?
Code:
if ($this->input->is_ajax_request())
{
    // ajax request
}
else
{
    // normal request
}

And as Tim mentioned it is very hard to help someone with out seeing the full code.
#10

[eluser]InsiteFX[/eluser]
Delete double post




Theme © iAndrew 2016 - Forum software by © MyBB