Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorklausEC
     
    I have the following template (add.tpl):

    <h1>_{Create outputs}</h1>
    <?php $f = $form_helper->form_for('output', $Output, array('url' => array('action' => 'create'))); ?>
    <table id="text">
    <tr><td>_{Relay A}:</td><td><?= $f->text_field('rAText'); ?></td></tr>
    <tr><td>_{Relay B}:</td><td><?= $f->text_field('rBText'); ?></td></tr>
    <tr><td>_{Relay C}:</td><td><?= $f->text_field('rCText'); ?></td></tr>
    <tr><td>_{Analog A}:</td><td><?= $f->text_field('aAText'); ?></td></tr>
    <tr><td>_{Analog B}:</td><td><?= $f->text_field('aBText'); ?></td></tr>
    </table>
    <button onclick="submitAndClosePopup();">_{Create}</button>
    <?= $f->end_form_tag(); ?>

    The javascript function is here:

    //submit the form, and close the popup afterwards.
    function submitAndClosePopup() {
    document.forms[0].submit();
    window.close();
    }

    and then finally, my create action in the controller looks like this:

    function create()
    {
    $this->output = new Output($this->params['output']);
    if(!$this->output->save()){
    $this->resources = $this->Resource->findAll();
    $this->render('add');
    }
    else {
    $this->redirectTo(array('controller' => 'meters', 'action' => 'index'));
    }
    }

    In firefox, everything works perfectly. In Internet Explorer, I get double entries in my database, for some reason, and thats not good :P

    Anyone got ideas as to how I can solve this problem?
    • CommentAuthorklausEC
     
    oh, one more thing to know:

    I have the following function in my outputs model:

    function afterSave() {
    $this->con = $this->getConnection();
    $sql = "UPDATE outputs SET box_id = " . $_SESSION["box_id"] . " WHERE id = " . $this->id . ";";
    $this->con->execute($sql);
    return true;
    }
    • CommentAuthorklausEC
     
    I've made the following changes:

    My action:

    function create()
    {
    $this->output = new Output($this->params['output']);
    $this->output->box_id = $_SESSION["box_id"];
    if(!$this->output->save()){
    $this->resources = $this->Resource->findAll();
    $this->render('add');
    }
    }

    in addition to this, I have deleted the function afterSave() in my model.

    This, altogether, is a better solution, but will nevertheless give me the exact same result.
    Works in Firefox, does not work in Internet Explorer.

    I would very much appreciate any help here, thank you.
    •  
      CommentAuthorbermi
     

    Looks like a JavaScript issue

    I guess IE treats the button tag as the submit button, so it would expect false to prevent the original form submission from happening.

    function submitAndClosePopup() {
      document.forms[0].submit();
      window.close();
      return false;
    }
    
    • CommentAuthorklausEC
     
    AHA!
    I found it! :)

    The issue is that the button is inside the form. Internet Explorer will per default see any button inside a form as a submit button. So when I submit manually in the javascript function, this submit will happen for the second time when using IE.

    The solution is: Move the button outside the form, and it will work perfectly! :)

    Thank you all for your time! :P

    EDIT: OK, you were faster than me... ^^