Welcome Guest, Not a member yet? Register   Sign In
Form posting with ajax error !
#1

[eluser]zyddee[/eluser]
Hello

Im trying to make an post validation with use of ajax.
But when i run and test it i get the error:

element has no properties
http://85.197.152.80/ci_partysmart/stati...ototype.js
Line 3484

View
Code:
<div id='mainDiv' class='newsDiv'>
<div class='newsHeader'>
<span class='Title'>&lt;?=$page['title']?&gt;</span>
<span class='newsTime'></span>
</div> &lt;!-- END newsHeader --&gt;
<div class='newsContent'>

&lt;!-- [ G Ä S T B O K ][ new-post ] --&gt;
<p>
&lt;?/*
=form_open('guestbook');
onSubmit='CheckCommentForm("output","guestbook/gb_validatePost");
*/?&gt;
&lt;form id='AddGBCommentForm' method='post'&gt;
<div class='comment'>
<table class='tform'>
&lt;!--row--&gt;
<tr> <td><b>Namn</b> (obligatoriskt)</td> <td><b>E-mail</b> (visas inte)</td> <td><b>Hemsida/Blog</b> (visas inte)</td> </tr>
&lt;!--row--&gt;
<tr>
<td>&lt;input type='text' name='author' id='author' value='&lt;?=$this-&gt;validation->author;?&gt;' class='form' /></td>
<td>&lt;input type='text' name='email' id='email' value='&lt;?=$this-&gt;validation->email;?&gt;' class='form' /></td>
<td>&lt;input type='text' name='page' id='page' value='&lt;?=$this-&gt;validation->page;?&gt;' class='form' /></td>
</tr>
&lt;!--row--&gt;
<tr> <td colspan='3'><b>Kommentar</b></td> </tr>
&lt;!--row--&gt;
<tr>
<td colspan='3'>&lt;textarea name='text' rows='5' cols='75' class='form'&gt;&lt;?=$this->validation->text;?&gt;&lt;/textarea&gt;</td>  
</tr>
</table>
&lt;input type='hidden' name='ip' id='ip' value='&lt;?=$_SERVER['REMOTE_ADDR'];?&gt;' /&gt;
&lt;input type='hidden' name='postid' id='postid' value='-1' /&gt;
&lt;input type='submit' value='Skicka' class='submit' /&gt;
</div> &lt;!-- END Add Comment Div --&gt;
&lt;/form&gt;
&lt;?=$formsuccess;?&gt;
<div id='output'>&lt;?=$this->validation->error_string; ?&gt;</div>
</p>
&lt;!-- END [ G Ä S T B O K ][ new-post ] --&gt;

</div> &lt;!-- END newsContent --&gt;
<div class='newsBottom'>
</div> &lt;!-- END newsBottom --&gt;
</div> &lt;!-- END newsDiv --&gt;

&lt;!-- [ G Ä S T B O K ][ view-posts ] --&gt;
<div id='guestbookDiv' style='float: left;' class='newsDiv'>
&lt;?=$views['guestbook']?&gt;
</div> &lt;!-- END guestbookDiv --&gt;
&lt;!-- END [ G Ä S T B O K ][ view-posts ] --&gt;

Controller
Code:
function gb_validatePost()
        {
            $this->validation->set_error_delimiters('<div class="error">', '</div>');
            $this->validation->error_string = null;            
            $this->validation->set_message('gb_validateIP', 'You have to wait a while before posting again.');
            // -INPUTS------------------------------
            // author, email , page , text , postid , ip
            $rules['author'] = 'required|min_length[3]|max_length[30]';
            $rules['email'] = 'required|valid_email';
            $rules['text'] = 'required|min_length[6]|max_length[500]';
            $rules['postid'] = 'required';
            $rules['ip'] = 'callback_gb_validateIP';
            $rules['page'] = 'prep_url';
            $this->validation->set_rules($rules);
            
            $fields['author'] = 'author';
            $fields['email'] = 'email';
            $fields['text'] = 'text';
            $fields['page'] = 'page';
            $fields['postid'] = 'postid';
            $fields['ip'] = 'ip';
            $this->validation->set_fields($fields);
                    
            if ( !$path = $this->uri->segment(1) )
            {
                $path = "guestbook";
            }            
            if ( ($this->validation->run() == FALSE) && ($this->template['page'] = $this->page->get($path)) )
            {
                $this->template['formsuccess'] = '';                
            }
            else if($this->template['page'] = $this->page->get($path))
            {
                $this->post_gb_post();
                $this->template['formsuccess'] = 'Ditt inlägg postades felfritt !';
                $this->posts->getComments( $this->input->post('postid') );
            }            
        }

Static
Code:
function CheckCommentForm()
{
    new Ajax.Updater('output', base_url+'guestbook/gb_validatePost', {
        encoding: 'UTF-8',
        method:'post',
        postBody:'author='+$F('author') + '&email;='+$F('email') + '&page;='+$F('page') + '&text;='+$F('text') + '&postid;='+$F('postid') + '&ip;='+$F('ip'),
        //onComplete:'showResponse',
        onComplete: function(t) {
            alert('complete');
        },                
        onFailure: function(t) {
            alert('Error ' + t.status + ' -- ' + t.statusText);
        }        
    });
    
    alert('checkcommentform');
    //return false; // To stop further processing.
}

window.onload = function () {
    $('AddGBCommentForm').onsubmit = function () {    
        CheckCommentForm();
        return false; // To stop further processing.    
    }
}

When i dont use the postbody in the static-page it all runs trough perfect. =/
Need help with this problem as fast as possible !

best regards !
#2

[eluser]zyddee[/eluser]
Ah, found the solution, ofcourse i forgot to set the ID-tag for one of the fields. :red: Confusedhut:




Theme © iAndrew 2016 - Forum software by © MyBB