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

[eluser]Tpojka[/eluser]
[quote author="scorpioniz" date="1410625708"]
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.. :///[/quote]
Can we asume that else block is not executed at all?

Again your code:
Code:
<?php if ( ! defined('BASEPATH') ) exit('No direct script access allowed');

class Someclass extends CI_Controller
{
public function __construct()
{
  parent::__construct();
}

public 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)//test here with true
  {
   $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);
  }
}
}
I put the comment after line no 16 to suggest reverse solution in case of executing code
Seems like else block is not executed at all, and your redirect function is just in it (already said).
#12

[eluser]Tim Brownlaw[/eluser]
Well scorpioniz insists that the insert and updates are working indicating that execution is falling into the else block... Which I find a little hard to believe with the provided code sample as $data doesn't exist locally in the function and I cannot see where it's being defined.

So it's obvious that IF the else block is being executed somethings going BANG halting execution... Or the redirect would be getting executed... We're flying blind here!

So A Quick check would be to do this...
Code:
<?php if ( ! defined('BASEPATH') ) exit('No direct script access allowed');

class Someclass extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
  }

  public 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
    {
      $event_id = 1; // Set this to something valid for testing
      redirect('user/event/show/'.$event_id); // NOW Does this work when the Form is Valid???
    }
  }
}
#13

[eluser]scorpioniz[/eluser]
[quote author="Tim Brownlaw" date="1410660500"]Well scorpioniz insists that the insert and updates are working indicating that execution is falling into the else block... Which I find a little hard to believe with the provided code sample as $data doesn't exist locally in the function and I cannot see where it's being defined.

So it's obvious that IF the else block is being executed somethings going BANG halting execution... Or the redirect would be getting executed... We're flying blind here!

So A Quick check would be to do this...
Code:
<?php if ( ! defined('BASEPATH') ) exit('No direct script access allowed');

class Someclass extends CI_Controller
{
  public function __construct()
  {
    parent::__construct();
  }

  public 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
    {
      $event_id = 1; // Set this to something valid for testing
      redirect('user/event/show/'.$event_id); // NOW Does this work when the Form is Valid???
    }
  }
}
[/quote]

sorry.. that i didn't put all my code.. :? i thought it will be easier to read.. but still nothing helping..
event if in else it is
Code:
$event_id = 1;
redirect('user/evet/show/'.$event_id);

it starts to load show page but later it still opens edit page..

so here is my all code of that function.. Smile

Code:
function edit($id = NULL, $test = null){
  if($id){
   $this -> data['page_title'] = 'Edit event';
  }else{
   $this -> data['page_title'] = 'Add event';
  }
  $this->data['includes'] = array('wizard', 'element', 'wysihtml5', 'form');

  $event = $this->database->GetSingle('events', array('id' => $id, 'userid' => $this->utilities->GetUserID()));
  $this->data['event'] = $event;
  
  if($this->form_validation->run('event/createedit') == FALSE){
   $this->ajaxValidation('event/createedit');
  }else{
  
   $img = $this->utilities->UploadEventImage('logo_img');
   $img2 = $this->utilities->UploadEventImage('portfolio_img');
  
   if($event != NULL && $event['logo_img'] != NULL && $img != ''){
    if( file_exists($event['logo_img']))
     unlink($event['logo_img']);
   }
   if($event != NULL && $event['portfolio_img'] != NULL && $img2 != ''){
    if( file_exists($event['portfolio_img']))
     unlink($event['portfolio_img']);
   }
  
   $privacy =($this->input->post('privacy') == 1) ? 1 : 0;
   $allowpublicregistration =($this->input->post('allowpublicregistration') == 1) ? 1 : 0;
  
   if($this -> input-> post('unlimited-people')){
    $max_quantity = 0;
   }else{
    $max_quantity = $this->input->post('max_quantity');
   }
  
   $data = array(
    'userid'  => $this->utilities->GetUserID(),
    'title'   => $this->input->post('title'),
    'description' => $this->input->post('description'),
    'startdate'  => $this->input->post('startdate') .' '. $this->input->post('starttime'),
    'enddate'   => $this->input->post('enddate') .' '. $this->input->post('endtime'),
    'location'  => $this->input->post('location'),
    'address'  => $this->input->post('address'),
    'webaddress' => $this->input->post('webaddress'),
    'privacy'  => $privacy,
    'allowpublicregistration' => $allowpublicregistration,
    'max_quantity' => $max_quantity,
    'about' => $this -> input -> post('about')
   );
  
   if($data['startdate'] > $data['enddate']){
    $error_message = 'The First Submission Date must be greater than the Last Submission Date.';
    return $this->form_validation->set_message($error_message);
   }
  
   if($img != ''){
    $data['logo_img'] = $img;
   }
   if($img2 != ''){
    $data['portfolio_img'] = $img2;
   }
  
   if($event == NULL){
    $this->database->Insert('events', $data);
    $event_id = $this -> database -> GetLastID();
    
    $default_template = $this->database->GetSingle('events_templates', array('default' => 1));
    $this -> database -> Insert('events_users_templates', array('event_id' => $event_id, 'template_id' => $default_template['id']));
   }else{
    $this->database->Update('events', $data, array('id' => $event['id']));
    $event_id = $event['id'];
   }
   var_dump($this->db->last_query());
   var_dump($event_id);
   exit;
  
   if($event_id != 0){
    redirect('user/event/show/'.$event_id);
   }
   exit;
  }
}

and i have made screenshots of my sql, and developer tools network tab with some comments in it, i hope it will help something.. :/

Screenshot
#14

[eluser]scorpioniz[/eluser]
well i did work around for this.. i made ajax call for submiting my form in view.. and then i check.. if i get $event_id an integer, i redirect to show page with
Code:
location.href = "<?=site_url('user/event/show');?>/"+event_id;
and for now it will work..
#15

[eluser]Tim Brownlaw[/eluser]
Can you clarify this point...
Quote:it starts to load show page but later it still opens edit page..

Does that mean that you start to see your "show page" but then it's redirecting to your "edit page"?
Or am I totally missing what the issue is here?
#16

[eluser]InsiteFX[/eluser]
Begging to sound like the old session problem with ajax.




Theme © iAndrew 2016 - Forum software by © MyBB