EllisLab text mark
Advanced Search
     
Form validation using xajax
Posted: 06 November 2008 07:35 AM   [ Ignore ]
Joined: 2008-11-06
2 posts

Hello,

I’m pretty new to CI.

I’ve a form and the validation without xajax works. Now I try to integrate xajax to validate the form. But the validation will not work. If I understand right, the CI validation uses the $_Post variables, but xajax submit the values in another way.

Does anyone has a solution for this?

 
Posted: 06 November 2008 07:38 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-03-31
242 posts

Can you share some code. We use some xajax in Webber but I’m not sure where your problem is.

 
Posted: 06 November 2008 08:00 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-11-06
2 posts

xajax:

function CreateNews()
    
{
        $this
->load->model('MyForm');
        
        
$data $this->MyForm->myvalidation();
            
        
$objResponse = new xajaxResponse();
                
$objResponse->Assign("content","innerHTML"$data);
                return 
$objResponse;        
        
}
    } 


Validation - Model MyForm:

function myvalidation(){
            
# Validations
          
$this->load->library('validation');
        
$this->load->helper('form');
          
          
$rules['fname'"required";
          
$rules['email'"required|valid_email";

        
$this->validation->set_rules($rules);
            
        
# Input and textarea field attributes
        
$data["fname"= array();
        
$data['email'= array();
        
$data['comments'= array();
                      
    
        if (
$this->validation->run() == FALSE)
        
{
            $this
->validation->set_fields($data);  
            
# Input and textarea field attributes
            
$data["fname"= array('name' => 'fname''id' => 'fname''value' => $this->validation->fname);
            
$data['email'= array('name' => 'email''id' => 'email''value' => $this->validation->email);
            
$data['comments'= array('name' => 'comments''id' => 'comments''rows' => 3'cols' => 40);
                    
            

             
$output $this->load->view('form_view'$datatrue);

        
}
        
else
        
{
                    $output 
$this->load->view('succes_view'$datatrue);
                
}
               
return $output;
       

Form:

<form name="test" id="test">
<
p><label for="fname">Full Name: </label><br /><?php echo form_input($fname); ?></p>
<
p><label for="email">E-mail: </label><br /><?php echo form_input($email); ?></p>

<
p>Please select one or more seminarsthat you would like to attend</p>
<
p><?php echo form_checkbox($purpose); ?> <label for="purpose">Purpose of Prayer</label></p>
<
p><?php echo form_checkbox($prepare); ?> <label for="prepare">Prepare for Prayer</label></p>
<
p><?php echo form_checkbox($principles); ?> <label for="principles">Principles of Prayer</label></p>
<
p><?php echo form_checkbox($power); ?> <label for="power">Power in Prayer</label></p>
<
p><label for="comments">Comments: </label><br /><?php echo form_textarea($comments); ?></p>
a href="#" xajax_CreateNews(xajax.getFormValues("test"false));'>Save 
 
Posted: 06 November 2008 08:43 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

CI’s validation uses POST variables to check things.  AJAX typically sends query strings, or GET variables to a URL, which in turn responds with the yes or no validation.  You’ll have to use some custom validation methods, whether they’re in the AJAX or your own controller/model.

 
Posted: 07 November 2008 08:09 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2007-03-31
242 posts
Aken - 07 November 2008 01:43 AM

CI’s validation uses POST variables to check things.  AJAX typically sends query strings, or GET variables to a URL, which in turn responds with the yes or no validation.  You’ll have to use some custom validation methods, whether they’re in the AJAX or your own controller/model.

So wrong!

@Haemo, you have to register the xajax function in your controller first. We do somwthing like this in Webber on the constructor (or where you need it…) function of the controller:

$this->xajax->registerFunction ( array( 'function_name', &$this'function_name' ) );
$this->xajax->processRequests (); 

Once the function registered and the requests sent out you must go out to the view and print the javascript that xajax uses to connect:

$this->xajax->printJavascript base_url () . '/path_to_xajax_js_folder/' 
 
Posted: 22 November 2008 09:19 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-11
224 posts

Hi guys
Sorry for my ignorance, but…
Is this a library with a custom xajax integrated into CI ?

$this->xajax->...

If so, where can I get it?

 Signature 

Joomla! and custom web apps

 
Posted: 22 November 2008 10:10 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2007-03-31
242 posts

No it’s not. You will have to download it from the xajax website.

 
Posted: 04 March 2009 05:33 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2008-07-31
194 posts
Aken - 07 November 2008 01:43 AM

So wrong!

@Haemo, you have to register the xajax function in your controller first. We do somwthing like this in Webber on the constructor (or where you need it…) function of the controller:

Even if it was true, you can set xAjax to use POST instead of GET.

 Signature 

Spam Helper | Html Helper | GPoll Library | IMAP Library

 
Posted: 10 April 2009 08:10 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2008-07-31
194 posts
manilodisan - 07 November 2008 01:09 PM

So wrong!

@Haemo, you have to register the xajax function in your controller first. We do somwthing like this in Webber on the constructor (or where you need it…) function of the controller:

$this->xajax->registerFunction ( array( 'function_name', &$this'function_name' ) );
$this->xajax->processRequests (); 

Once the function registered and the requests sent out you must go out to the view and print the javascript that xajax uses to connect:

$this->xajax->printJavascript base_url () . '/path_to_xajax_js_folder/' 

You explained how to setup xajax. This has nothing to do with the problem at hand, which by the way, still hasn’t been addressed…

 Signature 

Spam Helper | Html Helper | GPoll Library | IMAP Library