first sorry for my bad English I'm from an Spanish speaking country.
I'm kinda new in Web development, so I have some web project in hands and have been encountering problems with this requirement.
In a controller index() function I need to capture an ID attribute that passes thought a link like this:
echo '<td><a class=btn btn-default role=button data-toggle=modal href=#edituser data-href=admin/editar/' . $usuario->id . '><i class=glyphicon glyphicon-edit></i> Editar</a></td>';
So it can run
$data['editar_instructor'] = $this->user->obtener_datos_por_id($id);
and it can show the user data I'm trying to edit. I already have a JS code that captures the Modal form data and save to the DB.
//Wait until the DOM is fully loaded
$(document).ready(function(){
//Listen for the form submit
$('#edituser').submit(editUser);
});
//The function that handles the process
function editUser(event)
{
//Stop the form from submitting
event.preventDefault();
//Collect our form data.
var form_data = {
username : $([name='username']).val(),
password : $([name='password']).val(),
repassword : $([name='repassword']).val(),
JCCE : $([name='JCCE']).val(),
fullname : $([name='fullname']).val(),
privilegios : $([name='privilegios']).val()
};
var action = $(this).attr('data-href');
//Begin the ajax call
$.ajax({
url: action,
type: POST,
data: form_data,
dataType: json,
cache: false,
success: function (json) {
if (json.error==1)
{
//Show the user the errors.
$('#EditUserError').html(json.message);
} else {
//Hide our form
$('#edituserform').slideUp();
//Show the success message
$('#EditUserError').html(json.message).show();
}
}
});
}
that's working fine already, but I have no idea how to make the Modal load the data of an specific user.
Any suggestion, idea, critics, etc...? I'll appreciate anything.
Thanks in advance!