Background : I migrated a Codeigniter project to Windows 10 from Windows 7, in Windows 7, I was working with manual installation of Apache, PHP, Mysql but in Windows 10 I installed WAMP. Point to be noted here is that the mysqli is not working in this new setup, I have tried many things and asked questions here but to no avail. So I am working with mysql at the moment.
Problem : I started testing functioning of the website(migrated project) and found that the signup is not working which was working perfectly in windows 7 setup. The form is being submitted to the same controller which holds the form html. When the user clicks the submit button, the jquery do some stuff then returns true to let the form be submitted.
The problem is that, the controller does get loaded in response to the form submit but there is no post data, but if I change the action url to a test script, it shows that the form is being submitted properly and the post data is there.
Rerouting in application/config/routes.php :
$route['(?i)Signup/(:any)'] = 'Signup/index/$1';
Controller :
public function index ( $key = NULL )
{
/** Does nothing */
if ($_SERVER['REQUEST_METHOD'] == 'POST') print_r($_POST);
if ( isset ( $key ) )
{
return $this->_key( $key );
}
/** Register. */
if ( $this->input->post ( 'register_user' ) )
{
echo 'register_user';
return $this->_register ( );
}
/** File upload Ajax call. */
else if ( ! $this->input->post ( 'register_user' ) && $this->input->post ( 'gender' ) && $this->input->post ( 'ajaxUpload' ) )
{
echo 'ajaxUpload';
echo $this->_upload ( );
}
/** Email Validation Ajax Call. */
else if ( ! $this->input->post ( 'register_user' ) && $this->input->post ( 'email_validation' ) && $this->input->post ( 'email' ) )
{
echo 'email_validation';
echo $this->_email_available ( );
}
/** Default view. */
// If I submit form or not, this section is what gets executed
else
{
echo 'else';
$this->_default ( );
}
}
View file :
<form id="sign_up" action="<?php echo site_url ( ) . $this->router->fetch_class ( ) ;?>" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input id="register_user" type="hidden" name="register_user" value="Submit" />
---
---
<button type="submit" name="register_user" id="register_user" value="Submit">Submit</button>
</form>
JavaScript File : var sentinel = false;
$( '#sign_up' ).submit ( function ( event ) {
if ( ! sentinel )
{
var scriptUrl = $ ( '#sign_up' ).attr ( 'action' );
var data = new FormData ( );
/* Appaend form data with the formData object */
---
---
$.ajax ( {
method : 'POST', url : scriptUrl, data : data, cache : false, processData: false, contentType: false, dataType : 'json',
success : function ( data, textStatus, jqXHR ) {
/** Success uploading file, File saved to the server and server did not set the data.error variable/key. */
if ( typeof data.error === 'undefined' )
{
/** DO stuff */
sentinel = true;
$( '#sign_up' ).submit ( );
}
else
{
/** Set error message and do nothing. */
}
},
error : function ( jqXHR, textStatus, errorThrown )
{
alert ( jqXHR.responseText );
}
} );
}
// return false - cancels original submits until allowed
// returns true - allows a triggered submit
return sentinel;
}