Form submit not working in mobile chrome
I have a form which is working fine on desktop browsers, but on mobile browser (chrome on android) it just refresh page after submitted, and I tried to use type='submit' & type='button' & js to handle the submit action but all failed. The form is almost same as contact page included in 0.93 package, it email to admin after submitted. Would you let me know some solutions? Thanks.
Comments
controller:
<?php
class Info extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->library('session');
$this->load->library('form_builder');
if (!empty($_POST) AND $_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR'])
{
// put your processing code here... we show what we do for emailing. You will need to add a correct email address
if ($this->_process($_POST))
{
$this->session->set_flashdata('success', TRUE);
//redirect('info');
}
}
$fields = array();
$fields['name'] = array('required' => TRUE);
$fields['tel'] = array('required' => FALSE);
$fields['email'] = array('required' => TRUE);
$fields['message'] = array('required' => TRUE, 'type' => 'textarea');
$this->form_builder->set_fields($fields);
// will set the values of the fields if there is an error... must be after set_fields
$this->form_builder->set_validator($this->validator);
$this->form_builder->set_field_values($_POST);
$this->form_builder->display_errors = TRUE;
$this->form_builder->required_text = '*required fields';
$this->form_builder->form_attrs = array('method' => 'post', 'action' => 'info');
$vars['form'] = $this->form_builder->render();
// use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing
$page_init = array('location' => 'info');
$this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
$this->fuel_page->add_variables($vars);
$this->fuel_page->render();
}
function _process($data)
{
$this->load->library('validator');
/*
Set rules up here so we can pass them to the form_builder to display errors.
validator_helper contains the valid_email function... validator helper automatically gets' looded with Validation Class'
*/
$this->validator->add_rule('name', 'required', 'Please enter in an first name', $this->input->post('name'));
//$this->validator->add_rule('last_name', 'required', 'Please enter in an last name', $this->input->post('last_name'));
$this->validator->add_rule('email', 'valid_email', 'Please enter in a valid email', $this->input->post('email'));
$this->validator->add_rule('message', 'required', 'Please enter in an message', $this->input->post('message'));
if ($this->validator->validate())
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '********',
'smtp_pass' => '********',
'mailtype' => 'html',
'charset' => 'UTF-8',
'wordwrap' => true
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->load->helper('inflector');
// send email
$this->email->from($data['email'], $data['name']);
/*********************************************************************
YOU MUST FILL OUT THE CORRECT dev_email config in application/config/MY_config.php
AND/OR THE CORRECT TO email address
*********************************************************************/
// check config if we are in dev mode
if ($this->config->item('dev_mode'))
{
//echo $this->config->item('dev_email');
$this->email->to($this->config->item('dev_email'));
}
else
{
// need to fill this out to work
$this->email->to('********');
}
$this->email->subject('Website Contact Form');
$msg = "FROM KEEPLEARNING:
";
foreach($data as $key => $val)
{
$msg .= humanize($key, 3).":
".$val."
";
}
$this->email->message($msg);
// let her rip
if (!$this->email->send())
{
add_error('There was an error notifying');
return FALSE;
}
return TRUE;
}
}
}
Thanks!
$_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR']
I don't think your suggestion to change the .htaccess that way will work because of how CI figures out the URI path. Do you have access to your apache configuration? If so, you can set that folder as the document root.
Another problem, assume that I have permission to modify the apache configuration, and I changed DocumentRoot, then yes can access site with only root path, however, in fact, my home view is a blank page which is used for ajax only, it just like a template. After loaded, I check hash or pathname and load the content and insert by js, and now it can't load any content, just keep blank, the problem is the url of other page, e.g. localhost/home or localhost/#!home, are getting 500 return, I have no idea how to do..