CodeIgniter Forums

Full Version: Codeigniter with javascript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]haris244808[/eluser]
Hi there ...

i am working with codeigniter and trying to submit a form and then closing it with javascript...

i have a popup function...that i call from the parent page
Code:
< a href = "[removed]popup('controller/method/variable', 'Click', '400', '400')">Click</a>
and here is the function:
Code:
function reject_popup(url, name, width, height){
      var top = parseInt((screen.availHeight / 2) - (height / 2));
      var left = parseInt((screen.availWidth / 2) - (width / 2));
      var features = "location=1, status=1, scrollbars=1, width=" + width + ", height=" + height + ", top=" + top + ", left=" + left;
      window.open(url, name, features);
  }

and it opens this form:
Code:
&lt;?php echo form_open('state/validate_rejection/'.$file_results-&gt;sender_id.'/'.$this-&gt;session-&gt;userdata('id').'/'.$file_results-&gt;id, array('name'=&gt;'rejection_form', 'id'=&gt;'rejection_form', 'onsubmit'=&gt;'window.forms[0].submit();self.close();')); ?&gt;

   &lt;div class="form">

    <p>
     <label>Write the reason of Rejection?<span class='req'>* Required</label>
      &lt;textarea name="remarks" rows="8"  max-width:380px " autofocus required&gt;&lt;/textarea>
    </p>

   </div>
   &lt;!-- End Form --&gt;

   &lt;!-- Form Buttons --&gt;
   <div class="buttons">

    &lt;input type="button" class="button" value="cancel"  /&gt;
    &lt;input name="submit_rejection" id="submit_rejection" type="submit" class="button" value="Send" /&gt;

   </div>
   &lt;!-- End Form Buttons --&gt;

  &lt;?php echo form_close(); ?&gt;

as you can see the form action is a url that goes to a controller/method :
here is the method i use

Code:
function validate_rejection(){

  $this->form_validation->set_rules('remarks', 'Remarks', 'trim|required');

   if($this->form_validation->run() == TRUE){

    $sender_id = $this->uri->segment(3) ? $this->uri->segment(3) : 0;
    $user_id = $this->uri->segment(4) ? $this->uri->segment(4) : 0;
    $file_id = $this->uri->segment(5) ? $this->uri->segment(5) : 0;

//here a function from codigniter model is called, and returns true if query succeded, false if it failed
    $rejection = $this->files_model->reject_file($sender_id, $user_id, $file_id);

    if($rejection == TRUE){

     $this->session->set_flashdata('rejection_succ', 'Rejected Successfully');
     //redirect('home');
    }
    else{

     $this->session->set_flashdata('rejection_fail', 'Rejection of file Failed');
    }
   }
   else{
    $this->session->set_flashdata('remarks_validation_errors', validation_errors());
   }
}

and if the form is submitted successfully or failed it will set a flashdata

NOW I WANT THAT WHEN THE FORM IS SUBMITTED TO CHECK IF FORM IS FINISHED, RELOAD THE PARENT PAGE AND CLOSE THE POPUP....
Can anyone please help me achieve that...it is also a javascript case, but as long as i am working with codeigniter i thought that this will be the best place to post this thread?

El Forum

[eluser]TheFuzzy0ne[/eluser]
Firstly, your HTML is invalid, which may cause problems.

To refresh the parent page, you can do this:

Code:
window.opener.location.reload(true);

However, I suspect you need a little more logic so that the popup is only closed, and the parent window is only reloaded once validation passes.

El Forum

[eluser]haris244808[/eluser]
[quote author="TheFuzzy0ne" date="1364385463"]Firstly, your HTML is invalid, which may cause problems.

To refresh the parent page, you can do this:

Code:
window.opener.location.reload(true);

However, I suspect you need a little more logic so that the popup is only closed, and the parent window is only reloaded once validation passes.[/quote]

the only solution a achieved till now is that in controller after the query (checking if its true or false):
Code:
if($rejection == TRUE){
     echo " Rejected Successfully";
     //$this->session->set_flashdata('rejection_succ', 'Rejected Successfully');
     //redirect('home');
    }
    else{
     echo "Rejection Failed";
     //$this->session->set_flashdata('rejection_fail', 'Rejection  Failed');
     //redirect('home');
    }

and in the view on the form:

Code:
echo form_open('state/validate_rejection/'.$file_results->sender_id.'/'.$this->session->userdata('id').'/'.$file_results->id, array('onsubmit'=>'[removed]window.opener.location.reload(true);'));

this is one of the solutions i came up...
however i wanted to close popup window, reload parent (or redirect to the parent page and show flashdata)..
i couldnt achieve that....

Because to achieve that i need to use ja*vascri*pt inside controller...i mean that i need to redirect to parent and close the popup after i se the flashdata...(which means that the process will start after the form is submitted)

if it's possible to use ja*vascri*pt inside codeigniter controller that would be the solution...but as i know you cannot use inside a controller