CodeIgniter Forums

Full Version: AJAX questions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Carlos Mora[/eluser]
Hi ignitors,

I've been learning about using AJAX with forms, using FormTorch as a base.

This works fine, except for a minimal problem, that follows:

There is spans between label and inputs to show eventual errors like

Code:
<span class="error" id="nombre_error">
   </span>
The js routine that submits data updates a <span> label with errors, making

Code:
$("#nombre_error").html(data.nombre);

That makes the error message appears, but ads the error message surrounded by a &lt;p&gt; as in:

Code:
<span class="error" id="nombre_error">
            <p>El campo nombre es necesario.</p>
   </span>

where the extra &lt;p&gt; came from? that changes the presentation, &lt;p&gt; is a block tag.

El Forum

[eluser]behdesign[/eluser]
If the ajax data is coming from FormTorch (which I don't know) - then the formatting must be coming from there. Check to see what the output of the JSON data from FormTorch is sending, and remove the <p> tag if necessary.

El Forum

[eluser]Carlos Mora[/eluser]
Thank you behdesign.
And yes, i'm using formtoch's controller/action,

Code:
function process() {

    $this->load->library("validation");

    $fields['nombre'] = 'nombre';
    $this->validation->set_fields($fields);

    $rules['nombre'] = 'trim|required';
    $this->validation->set_rules($rules);

    if ($this->validation->run() == FALSE) {
        $data = array(
            'nombre' => $this->validation->nombre_error,
                        'success' => FALSE
            );
        echo json_encode($data);
    } else {
        $data = array(
            'nombre' => $this->input->post("nombre")
            );
                $this->admin->insertRecord($data);
                $data['success'] = TRUE;


    }
}

I forgot that "...by default, the Form Validation class adds a paragraph tag (&lt;p&gtWink around each error message shown. You can either change these delimiters globally or individually...."

Thanks again, you directed me to the solution,

Regards.