Welcome Guest, Not a member yet? Register   Sign In
Form validation using xajax
#1

[eluser]Unknown[/eluser]
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?
#2

[eluser]manilodisan[/eluser]
Can you share some code. We use some xajax in Webber but I'm not sure where your problem is.
#3

[eluser]Unknown[/eluser]
xajax:
Code:
function CreateNews()
    {
        $this->load->model('MyForm');
        
        $data = $this->MyForm->myvalidation();
            
        $objResponse = new xajaxResponse();
                $objResponse->Assign("content","innerHTML", $data);
                return $objResponse;        
        }
    }


Validation - Model MyForm:

Code:
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', $data, true);

        }
        else
        {
                    $output = $this->load->view('succes_view', $data, true);
                }
               return $output;
       }

Form:

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

<p>Please select one or more seminars, that you would like to attend</p>
<p>&lt;?php echo form_checkbox($purpose); ?&gt; <label for="purpose">Purpose of Prayer</label></p>
<p>&lt;?php echo form_checkbox($prepare); ?&gt; <label for="prepare">Prepare for Prayer</label></p>
<p>&lt;?php echo form_checkbox($principles); ?&gt; <label for="principles">Principles of Prayer</label></p>
<p>&lt;?php echo form_checkbox($power); ?&gt; <label for="power">Power in Prayer</label></p>
<p><label for="comments">Comments: </label><br />&lt;?php echo form_textarea($comments); ?&gt;</p>
a href="#" xajax_CreateNews(xajax.getFormValues("test", false));'>Save
#4

[eluser]Aken[/eluser]
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.
#5

[eluser]manilodisan[/eluser]
[quote author="Aken" date="1226036586"]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.[/quote]

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:

Code:
$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:
Code:
$this->xajax->printJavascript ( base_url () . '/path_to_xajax_js_folder/' )
#6

[eluser]CARP[/eluser]
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?
#7

[eluser]manilodisan[/eluser]
No it's not. You will have to download it from the xajax website.
#8

[eluser]Iverson[/eluser]
[quote author="Aken" date="1226036586"]
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:
[/quote]

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

[eluser]Iverson[/eluser]
[quote author="manilodisan" date="1226077764"]
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:

Code:
$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:
Code:
$this->xajax->printJavascript ( base_url () . '/path_to_xajax_js_folder/' )
[/quote]

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...




Theme © iAndrew 2016 - Forum software by © MyBB