Foros del Web » Programando para Internet » Jquery »

formulario validación Jquery y ajax

Estas en el tema de formulario validación Jquery y ajax en el foro de Jquery en Foros del Web. hola gente tengo problemas con estos formularios uno es de contactenos y el otro es de trabaje con nosotros ambos estan hecho en codeignater y ...
  #1 (permalink)  
Antiguo 14/09/2015, 14:29
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Mensaje formulario validación Jquery y ajax

hola gente tengo problemas con estos formularios uno es de contactenos y el otro es de trabaje con nosotros ambos estan hecho en codeignater y bueno quisiera saber si alguien me ayuda a organizarlos el problema es que cuando se le da a guardar o enviar la info la info se carga en el formulario de contacto voy a postear todos los codigos para que ustedes los vean y me ayuden gracias
  #2 (permalink)  
Antiguo 14/09/2015, 14:30
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

este es el controlador del primer formulario contact_us.php

Código PHP:
Ver original
  1. <?php
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4.  
  5. class Contact_Us extends Public_Controller {
  6.  
  7.     public function __construct() {
  8.         parent::__construct();
  9.         $models = array(
  10.             'contact_us_m',
  11.             'contact_us_emails_m',
  12.             'google_map_model',
  13.             'google_map_category_model'
  14.         );
  15.  
  16.         $this->load->model($models);
  17.         $this->lang->load('language');
  18.         $this->template
  19.                 ->append_js('module::jquery_validate.js')
  20.                 ->append_js('module::formvalidate.js');
  21.  
  22.         // idioma
  23.         $this->lang_code = $this->session->userdata('lang_code');
  24.         if (empty($this->lang_code)) {
  25.             $this->session->set_userdata(array('lang_code' => 'es'));
  26.             $this->lang_code = $this->session->userdata('lang_code');
  27.         }
  28.     }
  29.  
  30.     // -----------------------------------------------------------------
  31.  
  32.  
  33.  
  34.     public function index() {
  35.         // Datos de Contacto
  36.         $_contact_us = $this->contact_us_m->where('lang', $this->lang_code)->get_all();
  37.         $contact_us = array();
  38.         if (count($_contact_us) > 0) {
  39.             $contact_us = $_contact_us[0];
  40.         }
  41.  
  42.         $emails_area = $this->contact_us_m->sqlFormSelect('contact_us_emails_area', 'id', ($this->lang_code == 'es' ? 'title' : 'title_en'),
  43.             FALSE, null, null, $this->lang_code);
  44.  
  45.         $json_info_content = array();
  46.         $json_markers = array();
  47.  
  48.         $selectGoogleMaps = $this->contact_us_m->sqlFormSelect('google_map_categories', 'id', 'title', FALSE, 'outstanding', '1', $this->lang_code);
  49.         $moduleName = 'google_maps';
  50.  
  51.         if (!empty($selectGoogleMaps)) {
  52.             foreach ($selectGoogleMaps AS $item => $value) {
  53.                 $idCategory = $item;
  54.                 break;
  55.             }
  56.  
  57.             $google_map = $this->db
  58.                             ->select('*')
  59.                             ->from('google_maps AS gm')
  60.                             ->join('google_maps_categories AS gc', 'gc.google_map_id = gm.id', 'left')
  61.                             ->where('gc.category_id', $idCategory)
  62.                             ->get()->result();
  #3 (permalink)  
Antiguo 14/09/2015, 14:32
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

continuacion del codigo controlador
Código PHP:
Ver original
  1. // datos para el mapa de google        
  2.             $json_markers = array();
  3.             $json_info_content = array();
  4.  
  5.             if (!empty($google_map)) {
  6.                 foreach ($google_map AS $item) {
  7.                     $item->image = val_image($item->image);
  8.                     array_push($json_markers, array($item->adress . ', ' . $item->name, (double) $item->coordinate1, (double) $item->coordinate2));
  9.  
  10.                     $imageTogoogle = str_replace(site_url() . 'uploads/default/' . $moduleName . '/', "", $item->image);
  11.  
  12.                     array_push($json_info_content, array('image' => $imageTogoogle, 'adress' => $item->adress, 'title' => $item->name, 'moduleName'
  13.                         => $moduleName, 'schedule' => $item->schedule, 'description' => $item->description));
  14.                 }
  15.             }
  16.  
  17.             // mandamos los puntos
  18.             $json_markers = json_encode($json_markers);
  19.  
  20.  
  21.             // sacamos solo el nombre de la imagen
  22.             // mandamos los datos para el modal dentro del mapa
  23.             $json_info_content = json_encode($json_info_content);
  24.         }
  25.         $form = $this->db->where('id', 1)->get('others_conf_form_status')->row();
  26.         $this->template
  27.                 ->append_js('module::google_maps.js')
  28.                 ->set('form', $form)
  29.                 ->set('json_info_content', $json_info_content)
  30.                 ->set('json_markers', $json_markers)
  31.                 ->set('contact_us', $contact_us)
  32.                 ->set('selectGoogleMaps', $selectGoogleMaps)
  33.                 ->set('emails_area', $emails_area)
  34.                 ->build('contact_us_front');
  35.     }
  36.  
  37.     /*
  38.      * Enviar correo
  39.      */
  40.  
  41.     function send() {
  42.         $this->form_validation->set_rules('name', 'Nombre y Apellido', 'required|trim|max_length[100]');
  43.         $this->form_validation->set_rules('email', 'Correo', 'required|trim|valid_email|max_length[100]');
  44.         $this->form_validation->set_rules('phone', 'Teléfono', 'trim|max_length[30]');
  45.         $this->form_validation->set_rules('cell', 'Celular', 'trim|max_length[30]');
  46.         $this->form_validation->set_rules('company', 'Empresa/Organización', 'trim|max_length[100]');
  47.         $this->form_validation->set_rules('message', 'Mensaje', 'required|trim|max_length[455]');
  48.  
  49.         $statusJson = 'error';
  50.         $msgJson = 'Por favor intenta de mas tarde';
  51.  
  52.         if ($this->form_validation->run() === TRUE) {
  53.             $post = (object) $this->input->post(null);
  54.  
  55.             $email = $this->db->where('id', $post->id_email_area)->get('contact_us_emails_area')->row();
  56.  
  57.             // si el correo viene separado por ,
  58.             if (count($email) > 0) {
  59.                 $email = $email->email;
  60.                 if (strpos($email, ',') !== false) {
  61.                     $emails = explode(",", $email);
  62.                 }
  63.             }
  64.             setlocale(LC_ALL, "es");
  65.             date_default_timezone_set('America/Bogota');
  66.  
  67.             $data['post'] = array(
  68.                 'name' => $post->name,
  69.                 'email' => $post->email,
  70.                 'phone' => $post->phone,
  71.                 'cell' => $post->cell,
  72.                 'company' => $post->company,
  73.                 'city' => $post->city,
  74.                 'message' => $post->message,
  75.                 'cotizacion' => $post->cotizacion,
  76.                 'date' => date('Y-m-d H:i:s'),
  77.                 'lang' => $this->lang_code
  78. );
  #4 (permalink)  
Antiguo 14/09/2015, 14:34
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

continuacion del controlador

Código PHP:
Ver original
  1. //Validate sendmail
  2.             if ($this->contact_us_emails_m->insert($data['post'])) {
  3.                 // si estan separados por , mandamos los correos si no mandamos 1 solo                
  4.                 $id_email = $this->db->insert_id();
  5.                 $products_contact = $this->session->userdata('products_contact');
  6.  
  7.                 if (count($products_contact) > 0) {
  8.                     foreach ($products_contact as $item => $value) {
  9.                         $quote_array = array('id_product' => $item, 'id_email' => $id_email, 'pagina' => $products_contact[$item]['pagina']);
  10.                         $this->db->insert('contact_us_email_products', $quote_array);
  11.                     }
  12.                 }
  13.                 $array = array();
  14.                 $products = '';
  15.                 foreach ($products_contact AS $row => $value) {
  16.                     array_push($array, $row);
  17.                 }
  18.  
  19.  
  20.                 if (count($array) > 0) {
  21.                     $products = $this->db->select('pr.*')->from('products AS pr')->where_in('pr.id', $array)->get()->result();
  22.                 }
  23.                 $this->session->set_userdata(array('products_contact' => array()));
  24.  
  25.                 if (strpos($email, ',') !== false && !empty($emails) && count($emails) > 0) {
  26.                     foreach ($emails AS $row => $value) {
  27.                         $this->send_email_to_user($data['post'], $value, $products);
  28.                     }
  29.                 } else {
  30.                     $send = $this->send_email_to_user($data['post'], $email, $products);
  31.                 }
  32.  
  33.  
  34.                 if($send){
  35.                     $statusJson = '';
  36.                     $msgJson = 'Su mensaje ha sido enviado';
  37.                 }else{
  38.                     $statusJson = 'error';
  39.                     $msgJson = 'Error Mailing, Contact the Webmaster. x2020';
  40.                 }
  41.                
  42.             } else {
  43.                 $statusJson = 'error';
  44.                 $msgJson = 'Error Mailing, Contact the Webmaster';
  45.             }
  46.         } else {
  47.             $statusJson = 'error';
  48.             $msgJson = validation_errors();
  49.         }
  50.         echo json_encode(array('status' => $statusJson, 'msg' => $msgJson));
  51.     }
  52.  
  53.     public function detail($slug) {
  54.  
  55.         $return = $this->google_map_model->get_many_by('slug', $slug);
  56.         $return = $return[0];
  57.  
  58.         if (!$return)
  59.             redirect('google_maps');
  60.  
  61.         // Se convierten algunas variables necesarias para usar como slugs
  62.         $setter = array(
  63.             'image' => val_image($return->image),
  64.         );
  65.  
  66.         $google_map = array_merge((array) $return, $setter);
  67.  
  68.         $relation = $this->db->where('google_map_id', $google_map['id'])->get('google_maps_categories')->result();
  69.         $categories = array();
  70.         foreach ($relation as $item) {
  71.             $category = $this->google_map_category_model->get_many_by('id', $item->category_id);
  72.             $category = $category[0];
  73.             $categories[] = array(
  74.                 "title" => $category->title,
  75.                 "slug" => $category->slug
  76.             );
  77.         }
  78.  
  79.         // imagenes para slider
  80.         $images = $this->google_map_image_model->get_many_by('google_map_id', $google_map['id']);
  81.  
  82.         // datos para el mapa de google
  83.         // mandamos los puntos
  84.         $json_markers = json_encode(array(array($google_map['adress'] . ', Prueba-Cali', (double) $google_map['coordinate1'], (double) $google_map['coordinate2'])));
  85.  
  86.         // sacamos solo el nombre de la imagen
  87.         $imageTogoogle = str_replace(site_url() . 'uploads/default/' . $this->moduleName . '/', "", $google_map['image']);
  88.  
  89.         // mandamos los datos para el modal dentro del mapa
  90.         $json_info_content = json_encode(array(array('image' => $imageTogoogle, 'adress' => $google_map['adress'], 'title' => $google_map['name'], 'moduleName' => $this->moduleName, 'schedule' => $google_map['schedule'], 'description' => $google_map['description'])));
  91.  
  92.         $this->template
  93.                 ->append_js('module::google_maps.js')
  94.                 ->set('json_info_content', $json_info_content)
  95.                 ->set('json_markers', $json_markers)
  96.                 ->set('google_map', (object) $google_map)
  97.                 ->set('categories', $categories)
  98.                 ->set('images', $images)
  99.                 ->build('detail');
  100.     }
  #5 (permalink)  
Antiguo 14/09/2015, 14:35
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

final del controlador

Código PHP:
Ver original
  1. public function multiple_poins() {
  2.         $json_markers = array();
  3.         $json_info_content = array();
  4.         $statusJson = 'error';
  5.         $msgJson = 'Ocurrio un error al cargar los datos de google, porfavor intente más tarde';
  6.  
  7.         if (isset($_POST['idcategory'])) {
  8.             $idCategory = $_POST['idcategory'];
  9.  
  10.             $google_map = $this->db
  11.                             ->select('*')
  12.                             ->from('google_maps AS gm')
  13.                             ->join('google_maps_categories AS gc', 'gc.google_map_id = gm.id', 'left')
  14.                             ->where('gc.category_id', $idCategory)
  15.                             //->limit($pagination['limit'], $pagination['offset'])
  16.                             ->get()->result();
  17.  
  18.             if (!empty($google_map)) {
  19.                 foreach ($google_map AS $item) {
  20.                     $item->image = val_image($item->image);
  21.                     array_push($json_markers, array($item->adress . ', ' . $item->name, (double) $item->coordinate1, (double) $item->coordinate2));
  22.  
  23.                     $imageTogoogle = str_replace(site_url() . 'uploads/default/' . $this->moduleName . '/', "", $item->image);
  24.  
  25.                     array_push($json_info_content, array('image' => $imageTogoogle, 'adress' => $item->adress, 'title' => $item->name, 'moduleName' => $this->moduleName, 'schedule' => $item->schedule, 'description' => $item->description));
  26.                 }
  27.             }
  28.             $statusJson = '';
  29.             $msgJson = 'datos de google cargados correctamente';
  30.         }
  31.         // mandamos los puntos
  32.         $json_markers = json_encode($json_markers);
  33.  
  34.         // mandamos los datos para el modal dentro del mapa
  35.         $json_info_content = json_encode($json_info_content);
  36.  
  37.         echo json_encode(array('status' => $statusJson, 'msg' => $msgJson, 'json_markers' => $json_markers, 'json_info_content' => $json_info_content));
  38.     }
  39.  
  40.     /**
  41.      * Send an email
  42.      *
  43.      * @param array $comment The comment data.
  44.      * @param array $entry The entry data.
  45.      * @return boolean
  46.      */
  47.     private function send_email_to_user($data, $admin_email) {
  48.         $this->load->library('email');
  49.         $this->load->library('user_agent');
  50.  
  51.         return Events::trigger('email', array(
  52.             'name' => $data['name'],
  53.             'email' => $data['email'],
  54.             'phone' => $data['phone'],
  55.             'company' => $data['company'],
  56.             'city' => $data['city'],
  57.             'products' => $products,
  58.             'message' => $data['message'],
  59.             'cotizacion' => $data['cotizacion'],
  60.             'slug' => 'contact',
  61.             'to' => Settings::get('contact_email'),
  62.                 ), 'array');
  63.     }
  64.  
  65. }
  #6 (permalink)  
Antiguo 14/09/2015, 14:37
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

este es el controlador del formulario trabaje con nosotros work_with_us.ph
Código PHP:
Ver original
  1. <?php
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4.  
  5. class work_with_us extends Public_Controller {
  6.  
  7.     public function __construct() {
  8.         parent::__construct();
  9.          $models = array('work_with_us_m', 'work_with_us_emails_m');
  10.         $this->load->model($models);
  11.     }
  12.  
  13.     // -----------------------------------------------------------------
  14.  
  15.     public function index()
  16.     {
  17.         // Datos de Contacto
  18.         $_work_with_us = $this->work_with_us_m->get_all();
  19.         $work_with_us = array();
  20.         if (count($_work_with_us) > 0)
  21.         {
  22.             $work_with_us = $_work_with_us[0];
  23.         }
  24.  
  25.         $this->template
  26.                 ->set('work_with_us', $work_with_us)
  27.                 ->build('work_with_us_front');
  28.     }
  29.  
  30.     /*
  31.      *Enviar correo
  32.      */
  33.     function send()
  34.     {
  35.         $this->form_validation->set_rules('name', 'Nombre y Apellido', 'required|trim|max_length[100]');
  36.         $this->form_validation->set_rules('email', 'Correo', 'required|trim|valid_email|max_length[100]');
  37.         $this->form_validation->set_rules('phone', 'Teléfono', 'trim|max_length[30]');
  38.         $this->form_validation->set_rules('cell', 'Celular', 'trim|max_length[30]');
  39.         $this->form_validation->set_rules('company', 'Empresa/Organización', 'trim|max_length[100]');
  40.         $this->form_validation->set_rules('message', 'Mensaje', 'required|trim|max_length[455]');
  41.        
  42.         $statusJson = 'error';
  43.         $msgJson = 'Por favor intenta de mas tarde';
  44.        
  45.         if ($this->form_validation->run() === TRUE)
  46.         {
  47.             $_work_with_us = $this->work_with_us_m->get_all();
  48.             $work_with_us = array();
  49.             if (count($_work_with_us) > 0)
  50.             {
  51.                 $work_with_us = $_work_with_us[0];
  52.             }
  53.             $post = (object) $this->input->post(null);
  54.  
  55.             $data = array(
  56.                 'name' => $post->name,
  57.                 'email' => $post->email,
  58.                 'phone' => $post->phone,
  59.                 'cell' => $post->cell,
  60.                 'company' => $post->company,
  61.                 'message' => $post->message,
  62.             );
  63.            
  64.             // Se carga la imagen
  65.             $config['upload_path'] = './' . UPLOAD_PATH . '/work_with_us';
  66.             $config['allowed_types'] = 'doc|docx|txt|pdf|xls|xlsx';
  67.             $config['max_size'] = 2050;
  68.             $config['encrypt_name'] = true;
  69.    
  70.             $this->load->library('upload', $config);
  71.            
  72.             // imagen uno
  73.             $img = $_FILES['file']['name'];
  74.             $file = array();
  75.             $path = '';
  76.             if (!empty($img)) {
  77.                 if ($this->upload->do_upload('file'))
  78.                 {
  79.                     $datos = array('upload_data' => $this->upload->data());
  80.                     $path = UPLOAD_PATH . 'work_with_us/' . $datos['upload_data']['file_name'];
  81.                     $file = array('file' => $path);
  82.                     $data = array_merge($data, $file);
  83.                 } else {
  84.                     $this->session->set_flashdata('error', $this->upload->display_errors());
  85.                     redirect(base_url().'work_with_us');
  86.                 }
  87.             }
  88.            
  89.             //Validate sendmail
  90.             if( $this->work_with_us_emails_m->insert($data))
  91.             {
  92.                 // se envia el correo al administrador
  93.                 $this->send_email_to_user($data, $work_with_us->email, $path);
  94.                 // se envia el correo a la persona encargada de la pág
  95.                 $this->send_email_to_register($data, $work_with_us->email, $path);
  96.                 $statusJson = 'success';
  97.                 $msgJson = 'Su mensaje ha sido enviado';
  98.             }
  99.             else
  100.             {
  101.                 $statusJson = 'error';
  102.                 $msgJson = 'Error Mailing, Contact the Webmaster';
  103.             }
  104.         } else
  105.         {
  106.             $statusJson = 'error';
  107.             $msgJson = validation_errors();
  108.         }
  109.         $this->session->set_flashdata($statusJson, $msgJson);
  110.         redirect(base_url().'work_with_us');
  111.     }
  112.    
  113.     /**
  114.      * Send an email
  115.      *
  116.      * @param array $comment The comment data.
  117.      * @param array $entry The entry data.
  118.      * @return boolean
  119.      */
  120.     private function send_email_to_user($data, $admin_email, $path)
  121.     {
  122.         $this->load->library('email');
  123.         Events::trigger('email', array(
  124.             'name' => $data['name'],
  125.             'email' => $data['email'],
  126.             'phone' => $data['phone'],
  127.             'company' => $data['company'],
  128.             'message' => $data['message'],
  129.             'slug' => 'work_with_us',
  130.             'attach' => array( 0 => $path),
  131.             /*'email' => Settings::get('contact_email'), // se manda el correo a al de la configuración del pyro*/
  132.             'to' => $admin_email,
  133.         ), 'array');
  134.     }
  135.    
  136.     // envia un correo a la persona que registro la hoja de vida
  137.     private function send_email_to_register($data, $admin_email, $path)
  138.     {
  139.         $this->load->library('email');
  140.         Events::trigger('email', array(
  141.             'name' => $data['name'],
  142.             'email' => $data['email'],
  143.             'phone' => $data['phone'],
  144.             'company' => $data['company'],
  145.             'message' => $data['message'],
  146.             'slug' => 'work_with_us_register',
  147.             'attach' => array( 0 => $path),
  148.             /*'email' => Settings::get('contact_email'), // se manda el correo a al de la configuración del pyro*/
  149.             'to' => $data['email'],
  150.         ), 'array');
  151.     }
  152. }
  #7 (permalink)  
Antiguo 14/09/2015, 15:12
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

este es el formulario contactenos

Código PHP:
Ver original
  1. <!-- CONTACTENOS -->
  2. <section id="contactenos" class="sec_hor">
  3.  
  4. <div id="baseurl" class="hide">{{ url:site }}</div>
  5. <div id="json_markers" class="hide">{{ json_markers }}</div>
  6. <div id="json_info_content" class="hide">{{ json_info_content }}</div>
  7.  
  8. <div class="container">
  9.  
  10.     <h1 class="tit-gen">
  11.         Contáctenos
  12.     </h1>
  13.  
  14.     <div class="row">
  15.  
  16.         <div class="col s12 l5">
  17.             <div id="loading_contacts"></div>
  18.            
  19.                 <div class="s2"></div><?php echo form_open(site_url('contact_us/send'), 'class="crud form_contac_ajax"'); ?>
  20.                 <div class="input-field">
  21.                     <input id="nombre" type="text" class="validate name" name="name" value="<?php echo set_value('nombre') ?>">
  22.                     <label for="nombre">Nombre</label>
  23.                 </div>
  24.                 <div class="input-field ">
  25.                     <input id="email" type="text" class="validate email" name="email" value="<?php echo set_value('correo') ?>">
  26.                     <label for="email">Correo Electrónico</label>
  27.                 </div>
  28.                 <div class="input-field ">
  29.                     <input id="phone" type="text" class="validate phone" name="phone" value="<?php echo set_value('telefono') ?>">
  30.                     <label for="phone">Teléfono</label>
  31.                 </div>
  32.                 <div class="input-field ">
  33.                     <input id="cell" type="text" class="validate cell" name="cell" value="<?php echo set_value('cell') ?>">
  34.                     <label for="cell">Celular</label>
  35.                 </div>
  36.                 <div class="input-field ">
  37.                     <input id="company" type="text" class="validate company" name="company" value="<?php echo set_value('company') ?>">
  38.                     <label for="company">Compañia</label>
  39.                 </div>
  40.                 <div class="input-field ">
  41.                     <input id="city" type="text" class="validate city" name="city" value="<?php echo set_value('city') ?>">
  42.                     <label for="city">Ciudad</label>
  43.                 </div>
  44.                 <div class="input-field hide">
  45.                     <?php echo form_dropdown('id_email_area', $emails_area, set_value('id_email_area'), 'id="id_email_area" class="select_contact" style="display: block;"'); ?>
  46.                     <br><label for="id_email_area">Areas</label>
  47.                 </div>
  48.                 <div class="input-field">
  49.                     <textarea id="textarea1" name="message" class="materialize-textarea message"></textarea>
  50.                     <label for="textarea1">Mensaje</label>
  51.                 </div>
  52.                 <div class="input-field">
  53.                     <textarea id="textarea2" name="cotizacion" class="materialize-textarea message"></textarea>
  54.                     <label for="textarea2">Solicitar cotización</label>
  55.                 </div>
  56.  
  57.  
  58.                 <input type="submit" class="waves-effect waves-light btn right" name="btnAction" value="Enviar">
  59.                
  60.                 <div class="clear"></div>
  61.                 <?php echo form_close(); ?>
  62.            
  63.         </div>
  64.  
  65.         <div class="col s12 l7">
  66.  
  67.             <div class="cont-select_maps">
  68.                 <?php echo form_dropdown('id_google_map', $selectGoogleMaps, (isset($id_google_map) ? $id_google_map : set_value('id_google_map')), 'id="changeGoogleMap"'); ?>
  69.             </div>
  70.  
  71.             <div id="map_loader"></div>
  72.             <div id="map_wrapper">
  73.                 <div id="map_canvas" class="mapping"></div>
  74.             </div>
  75.  
  76.             <div class="contact-data">
  77.                 <h3 class="tit-gen-3">Datos de Contacto</h3>
  78.                 <ul class="dat_contact">
  79.                     <li><i class="fa fa-map-marker"></i>
  80.                         <?php echo (isset($contact_us->adress) ? $contact_us->adress : ''); ?></li>
  81.                     <li><i class="fa fa-phone"></i>
  82.                         <?php echo (isset($contact_us->phone) ? $contact_us->phone : ''); ?></li>
  83.                     <li><i class="fa fa-envelope"></i>
  84.                         <?php echo (isset($contact_us->email) ? $contact_us->email : ''); ?></li>
  85.                     <div class="s2"></div>
  86.                 </ul>
  87.             </div>
  88.         </div>
  89.  
  90.     </div>
  91.  
  92. </div>
  93.  
  94. </section>
  #8 (permalink)  
Antiguo 14/09/2015, 15:17
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

este es el formvalidate.js

Código Javascript:
Ver original
  1. $(document).ready(function()
  2. {
  3.     var base_url = $('#baseurl').html();  // seleccionamos la base url de un div
  4.  
  5.     // personalizamos los mensajes
  6.     jQuery.extend
  7.             (
  8.                     jQuery.validator.messages,
  9.                     {
  10.                         required: "Este campo es obligatorio",
  11.                         remote: "Por favor corrija este campo",
  12.                         email: "Por favor escriba un correo válido",
  13.                         url: "Por favor escriba una url válida.",
  14.                         date: "Por favor escriba una fecha válida.",
  15.                         dateISO: "Por favor escriba una fecha válida (ISO).",
  16.                         number: "El campo debe ser numerico.",
  17.                         digits: "Por favor use sólamente dígitos.",
  18.                         creditcard: "Por favor introduzca un número de tarjeta de crédito válido.",
  19.                         equalTo: "Por favor introduzca el mismo valor del anterior.",
  20.                         accept: "Por favor introduzca un valor con una extensión válida.",
  21.                         maxlength: jQuery.validator.format("Por favor escriba máximo {0} caracteres."),
  22.                         minlength: jQuery.validator.format("Por favor escriba mínimo {0} caracteres."),
  23.                         rangelength: jQuery.validator.format("Por favor escriba un valor entre {0} y {1} caracteres de longitud."),
  24.                         range: jQuery.validator.format("Por favor escriba un valor entre {0} y {1}."),
  25.                         max: jQuery.validator.format("Por favor introduzca un valor menor o igual a {0}."),
  26.                         min: jQuery.validator.format("Por favor introduzca un valor mayor o igual a {0}.")
  27.                     },
  28.             $.validator.addMethod
  29.                     (
  30.                             "date",
  31.                             function(value, element) {
  32.                                 //return Funciones_JS_Sinergia.esFecha(value);
  33.                             },
  34.                             "Por favor digite una fecha válida usando el formato dd-mm-aaaa."
  35.                             )
  36.                     );
  37.  
  38.     // contactenos
  39.     $('.form_contac_ajax').validate({
  40.         rules: {
  41.             name: {required: true, minlength: 2, maxlength: 100},
  42.             email: {required: true, email: true, maxlength: 100},
  43.             phone: {required: true, minlength: 5, maxlength: 30},
  44.             cell: {minlength: 10, maxlength: 30},
  45.             company: {maxlength: 100},
  46.             message: {required: true, maxlength: 455},
  47.         },
  48.         highlight: function(element) {
  49.             $(element).addClass('form_txt_error');
  50.             $(element).removeClass('error');
  51.         },
  52.         unhighlight: function(element) {
  53.             $(element).removeClass('form_txt_error');
  54.         },
  55.         focusInvalid: true,
  56.         onfocusout: false,
  57.         submitHandler: function(event)
  58.         {
  59.             llamadaAjaxContact('.form_contac_ajax');  // mandamos el nombre del formulario
  60.         }
  61.     });
  62.  
  63.     // funcion de jquery donde recibimos el nombre del formulario
  64.     function llamadaAjaxContact(formname)
  65.     {
  66.         $.ajax({
  67.             url: $(formname).attr('action'),
  68.             type: 'POST',
  69.             dataType: 'json',
  70.             data: $(formname).serialize(),
  71.             beforeSend: function()
  72.             {
  73.                 $('#loading_contacts').html('<img src="' + base_url + 'uploads/default/loading.gif" width="28" height="28"/>');
  74.             },
  75.             success: function(data)
  76.             {
  77.                 $('#loading_contacts').html(data.msg);
  78.                 if (data.status == 'error') {
  79.                     $('#loading_contacts').html('<div style="color: red">' + data.msg + '</div>');
  80.                 } else {
  81.                     $('#loading_contacts').html('<div style="color: green">' + data.msg + '</div>');
  82.  
  83.                 }
  84.             },
  85.             error: function(err)
  86.             {
  87.                 alert("Ocurrió un error. Por favor inténtelo de nuevo.");
  88.             }
  89.         });
  90.     }
  91.  
  92. });
  93. $(document).ready(function() {
  94.  
  95.     $(document).on("click ", ".destroy_item_contact", function(event) {
  96.         event.preventDefault();
  97.         var id_product = '#prd_' + $(this).data('id');
  98.         $.ajax({
  99.             url: $(this).data('url'),
  100.             type: 'POST',
  101.             beforeSend: function() {
  102. //                $('#content_product').html('<img src="' + base_url + 'uploads/default/loading.gif" width="28" height="28"/>');
  103.             },
  104.             success: function(data) {
  105.                 if (data === '"exito"') {
  106.                     $(id_product).remove();
  107.                 } else {
  108.                     alert('ha ocurrido un error intentelo denuevo.');
  109.                 }
  110.             },
  111.             error: function(err) {
  112.                 alert("Ocurrió un error. Por favor inténtelo de nuevo.");
  113.             }
  114.         });
  115.     });
  116. });
  #9 (permalink)  
Antiguo 14/09/2015, 15:19
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

este es el ajax de los formularios.

Código Javascript:
Ver original
  1. $(document).ready(function()
  2. {
  3.     var base_url = $('#baseurl').html();  // seleccionamos la base url de un div
  4.  
  5.     $(document).on("click", ".view_message", function(event)
  6.     {
  7.         event.preventDefault();
  8.         $.ajax({
  9.             type: "POST",
  10.             url: base_url + $(this).attr('href'),
  11.             beforeSend: function() {
  12.                 $("#cboxContent").html('<img src="' + base_url + 'uploads/default/loading.gif" width="28" height="28"/>');
  13.             },
  14.             success: function(html) {
  15.                 $("#cboxContent").html(html);
  16.             },
  17.             error: function(err)
  18.             {
  19.                 alert("Ocurrió un error. Por favor inténtelo de nuevo.");
  20.             }
  21.         });
  22.     });
  23.  
  24.  
  25.     var subCatArrayOld = new Array();
  26.  
  27.     /*$(document).on("mousemove", ".sortable", function(event) // evento mouseover o mousemove
  28.      {*/
  29.     $(".sortable").sortable
  30.             ({
  31.                 update: function()
  32.                 {
  33.  
  34.                 },
  35.                 create: function(event, ui)
  36.                 {
  37.                     // guardamos la posición de las categorias en un array global
  38.                     if (subCatArrayOld.length == 0)
  39.                     {
  40.                         subCatArrayOld = $(this).sortable("toArray");
  41.                     }
  42.                 },
  43.                 stop: function(event, ui)
  44.                 {
  45.                     idParent = $(this).parents().eq(0).attr('id');
  46.                     if (isNaN(idParent))
  47.                     {
  48.                         idParent = 0;
  49.                     }
  50.                     subCatArray = $(this).sortable("toArray");
  51.                     // si la posición de los widgets cambio, guardamos el cambio en la BD
  52.                     console.log(subCatArray);
  53.                     console.log(subCatArrayOld);
  54.                     if (subCatArrayOld.compare(subCatArray) === false)
  55.                     {
  56.                         Sortable($(this), subCatArray, idParent);
  57.                     }
  58.                 },
  59.             });
  60.     //});
  61.  
  62.     function Sortable(element, subCatArray, idParent)
  63.     {
  64.         $.ajax
  65.                 ({
  66.                     type: "POST",
  67.                     dataType: "json",
  68.                     url: base_url + 'admin/contact_us/orden_categories/',
  69.                     data: ({subCatArray: subCatArray, idParent: idParent}),
  70.                     beforeSend: function()
  71.                     {
  72.                         $('#ajax_message').html('<img src="' + base_url + 'uploads/default/loading.gif" width="28" height="28" class="img_loadig" />');
  73.                     },
  74.                     success: function(data)
  75.                     {
  76.                         //$("#carga").empty();
  77.                         //alert(data.msg);
  78.                         if (data.status == 'error')
  79.                         {
  80.                             $('#ajax_message').html('<div style="color: red">' + data.msg + '</div>');
  81.                             //location.reload();
  82.                         }
  83.                         else
  84.                         {
  85.                             $('#ajax_message').html('<div style="color: green">' + data.msg + '</div>');
  86.                         }
  87.                     },
  88.                     error: function(err)
  89.                     {
  90.                         alert("Ocurrió un error. Por favor inténtelo de nuevo.", err);
  91.                         //$("#carga").empty();
  92.                     }
  93.                 });
  94.     }
  95.  
  96.     // comparar dos array para saber si son iguales
  97.     Array.prototype.compare = function(array)
  98.     {
  99.         // if the other array is a falsy value, return
  100.         if (!array)
  101.             return false;
  102.  
  103.         // compare lengths - can save a lot of time
  104.         if (this.length != array.length)
  105.             return false;
  106.  
  107.         for (var i = 0; i < this.length; i++) {
  108.             // check if we have nested arrays
  109.             if (this[i] instanceof Array && array[i] instanceof Array) {
  110.                 // recurse into the nested arrays
  111.                 if (!this[i].compare(array[i]))
  112.                     return false;
  113.             }
  114.             else if (this[i] != array[i]) {
  115.                 // Warning - two different object instances will never be equal: {x:20} != {x:20}
  116.                 return false;
  117.             }
  118.         }
  119.         return true;
  120.     }
  121. });
  #10 (permalink)  
Antiguo 14/09/2015, 15:22
Avatar de joseherran  
Fecha de Ingreso: septiembre-2015
Ubicación: cali valle
Mensajes: 23
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: formulario validación Jquery y ajax

Cita:
Iniciado por joseherran Ver Mensaje
hola gente tengo problemas con estos formularios uno es de contactenos y el otro es de trabaje con nosotros ambos estan hecho en codeignater y bueno quisiera saber si alguien me ayuda a organizarlos el problema es que cuando se le da a guardar o enviar la info la info se carga en el formulario de contacto voy a postear todos los codigos para que ustedes los vean y me ayuden gracias
aqui dejo el codigo quien quiera y puede ayudarme por favor quedo atento el formulario contactenos y trabaje con nosotros estan en una pagina one page cualquier caso los dos formularios deben quedar registrando individualmente no entre ellos y el formulario trabaje con nosotros debe de cargar en la pagina no que me redireccione a la interna

Etiquetas: ajax, formulario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:50.