CodeIgniter Forums
AJAX questions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: AJAX questions (/showthread.php?tid=29924)



AJAX questions - El Forum - 04-26-2010

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


AJAX questions - El Forum - 04-26-2010

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


AJAX questions - El Forum - 04-26-2010

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