Welcome Guest, Not a member yet? Register   Sign In
prototype ajax.updater response help
#3

[eluser]sszynrae[/eluser]
Code:
function ajaxaddcomment()
{
    $_POST['date'] = mktime(); $_POST['ip'] = $this->input->ip_address();
    $this->blog_model->get_validation_rules(true);
    if ($this->input->post('notify') == 1) { $_POST['notify'] = 1; } else { $_POST['notify'] = 0; }
    if ( $this->validation->run() == FALSE )
    {
        echo $this->validation->error_string;
    }
    else {
        unset($_POST['securitycode']);
        $this->db->insert('comments', $_POST);
        $this->db->where('date',$_POST['date']);
        $this->db->where('name',$_POST['name']);
        $query = $this->db->get('comments', 1);
        foreach($query->result_array() as $newcomment) {
            echo $this->load->view('entries/single-comment', array('comment'=>$newcomment));
        }
    }            
}

it's the case validation->run == false that i want to make ajax aware of.
here's my j.script:

Code:
document.observe("dom:loaded", function() {
    $('add_comment_form').observe('submit', add_comment);
});
function add_comment(e) {
    Event.stop(e);
    k = Math.floor(Math.random()*10000000)
    $('subbtn').disabled=true; //stops submit button from working
    new Effect.Appear('new'); //make new comments container visible
    $('new').insert('<div id="new'+k+'"></div>'); //create new div to contain new comment inside container
    pars = $('add_comment_form').serialize();
    new Ajax.Updater ('new'+k, base_url+'entries/ajaxaddcomment',
                      {method:'post', postBody: pars});
    new Effect.Appear('new'+k);
    new Effect.Highlight('new'+k, {delay: 0, startcolor: '#707000', endcolor: '#002a00'});
    addobserve.delay(0.7);
}
function addobserve(){
    $('new'+k).down('.del').observe('click', remove_comment);
}

basically i want my javascript to do something different if validation->run == false, as of now it's being treated as a success and echoes the validation error as if it were a comment.

and yeah, this probably is not the most effective code to to this stuff, but i'm new and it gets the half the job done. i'm happy to receive any pointers in effectiveness though!


edit: forgot the views: the important divs in comment.php
Code:
<div id="cmntz" class="tabz">
    <div class="pagetitle">Comments</div>
        &lt;?php if ($query->num_rows() > 0): ?&gt;
    &lt;?php foreach($query->result_array() as $comment): ?&gt;
        &lt;?=$this->load->view('entries/single-comment', array('comment'=>$comment), true) ?&gt;
    &lt;?php endforeach; ?&gt;
    &lt;?php endif; ?&gt;
    <div id="new" style="display:none"></div>
</div>
<br />

single-comment.php is not really that relevant to my question, nor is it easy to read, but here you go. it is just a div with a table with my styled comment layout. there's a delete button there that gets a listener added by the script.
Code:
<div class="cmnt" id="&lt;?=$comment['cid']?&gt;"><table class="tcmnt"><tr>
    <td width="30" valign="center">&lt;?=$this->blog_model->gravatar($comment['email'],40,"ava")?&gt;</td>
    <td width="150" align="center" valign="top"><b>
    &lt;?php if ($comment['website']): ?&gt; <a href="&lt;?=$comment['website']?&gt;">&lt;?php endif;?&gt;&lt;?=$comment['name']?&gt;&lt;?php if ($comment['website']):?&gt;</a>&lt;?php endif;?&gt;
    &lt;?php if ($comment['notify'] == 1):?&gt; <a title="&lt;?=$comment['name']?&gt; has subscribed to this post"><img class="icon" src="/imgs/mailbutton.gif"></a>
    &lt;?php endif; ?&gt;</b><br>&lt;?=date("H:i j.M'y",$comment['date'])?&gt;</td>
    <td valign="top">&lt;?=nl2br($comment['commenttext'])?&gt;</td>
    <td align="center" width="40" valign="top">&lt;?=anchor('entries/edit_comment/'.$comment['cid'], 'Edit');?&gt;
    <a id="del" class="del" href="&lt;?=site_url('entries/delete_comment/'.$comment['cid'])?&gt;" title="delete comment">[-]</a>
    <a href="">Reply</a><br /></td>
</tr></table></div>


Messages In This Thread
prototype ajax.updater response help - by El Forum - 02-19-2009, 08:43 AM
prototype ajax.updater response help - by El Forum - 02-19-2009, 09:39 AM
prototype ajax.updater response help - by El Forum - 02-19-2009, 11:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB