Closed Firefly16 closed 8 years ago
i've used the print_errors
like this
if($this->aauth->create_user($email, $password $name)){
//success
redirect ($another_page);
}else{
//failure on creation
echo $this->aauth->print_errors();
}
the $divider = '<br />'
is default.
if you write me more of your code, then i can better help you :smiley:
idk if this work echo $data['errors'] = $this->aauth->print_errors($divider = '<br />');
try it without $divider =
i think this is your problem.
if you want to change the divider only then write it like this
echo $data['errors'] = $this->aauth->print_errors('<hr />');
example with a <hr />
as divider.
public function create_user(){
$this->form_validation->set_rules('nickname', 'Nickname', 'trim|required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email');
$this->form_validation->set_rules('address', 'Address', 'trim|min_length[2]|alpha_numeric_spaces');
if($this->form_validation->run()){
// Le formulaire est valide
$data['nickname'] = $this->input->post('nickname');
$data['password'] = $this->input->post('password');
$data['address'] = $this->input->post('address');
$data['email'] = $this->input->post('email');
$query = $this->db->get('aauth_users');
foreach ($query->result() as $row){
if($row->email == $data['email']){
$exist = 1;
}
}
if(isset($exist) && $exist == 1){ // a faire avec les erros de aauth
$data['exist'] = $exist;
echo $this->aauth->print_errors();
$this->load->view('inscription_view',$data);
}else{
$this->aauth->create_user($data['email'], $data['password'], $data['nickname']);
if(isset($data['address']) && $data['address'] != ''){ // test d'ajout de l'addresse
$this->aauth->set_user_var('address', $data['address']);
}
$this->load->view('confirmation_view',$data);
}
}else{
// Le formulaire est invalide
$data['signup'] = 1;
$this->load->view('inscription_view',$data); //inscription_view
}
}
I tried your echo $this->aauth->print_errors();
doesn't work too :s
public function create_user(){
$this->form_validation->set_rules('nickname', 'Nickname', 'trim|required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email');
$this->form_validation->set_rules('address', 'Address', 'trim|min_length[2]|alpha_numeric_spaces');
if($this->form_validation->run()){
// Le formulaire est valide
$data['nickname'] = $this->input->post('nickname');
$data['password'] = $this->input->post('password');
$data['address'] = $this->input->post('address');
$data['email'] = $this->input->post('email');
if($this->aauth->create_user($data['email'], $data['password'], $data['nickname'])){
if(isset($data['address']) && $data['address'] != ''){ // test d'ajout de l'addresse
$this->aauth->set_user_var('address', $data['address']);
}
$this->load->view('confirmation_view',$data);
}else{
echo $this->aauth->print_errors();
$this->load->view('inscription_view',$data);
}
}else{
// Le formulaire est invalide
$data['signup'] = 1;
$this->load->view('inscription_view',$data); //inscription_view
}
}
try this your extra check for existing mail is not needed
the create_user()
creates the error messages.
you skipped it trough your extra check.
an other way are to create your own error message instead of Aauth's
the other way :smile:
public function create_user(){
$this->form_validation->set_rules('nickname', 'Nickname', 'trim|required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email');
$this->form_validation->set_rules('address', 'Address', 'trim|min_length[2]|alpha_numeric_spaces');
if($this->form_validation->run()){
// Le formulaire est valide
$data['nickname'] = $this->input->post('nickname');
$data['password'] = $this->input->post('password');
$data['address'] = $this->input->post('address');
$data['email'] = $this->input->post('email');
$query = $this->db->get('aauth_users');
foreach ($query->result() as $row){
if($row->email == $data['email']){
$exist = 1;
}
}
if(isset($exist) && $exist == 1){ // a faire avec les erros de aauth
$data['exist'] = $exist;
$this->aauth->error('<YOUR ERROR MESSAGE>');
echo $this->aauth->print_errors();
$this->load->view('inscription_view',$data);
}else{
$this->aauth->create_user($data['email'], $data['password'], $data['nickname']);
if(isset($data['address']) && $data['address'] != ''){ // test d'ajout de l'addresse
$this->aauth->set_user_var('address', $data['address']);
}
$this->load->view('confirmation_view',$data);
}
}else{
// Le formulaire est invalide
$data['signup'] = 1;
$this->load->view('inscription_view',$data); //inscription_view
}
}
In fact my extra check was to display a php block on the view because i wasn't able to display the aauth message error, but now it work, thx you :)
And, as long as you are here, the set_user_var dont give errors but i cant find my "address" row in all aauth table :s
(I read in an other post that create the address row before was not usefull)
which version you use without the extra check or with the extra check?
without, your first solution :)
ok
public function create_user(){
$this->form_validation->set_rules('nickname', 'Nickname', 'trim|required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[60]|alpha_numeric_spaces');
$this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email');
$this->form_validation->set_rules('address', 'Address', 'trim|min_length[2]|alpha_numeric_spaces');
if($this->form_validation->run()){
// Le formulaire est valide
$data['nickname'] = $this->input->post('nickname');
$data['password'] = $this->input->post('password');
$data['address'] = $this->input->post('address');
$data['email'] = $this->input->post('email');
$user_id = $this->aauth->create_user($data['email'], $data['password'], $data['nickname'])
if($user_id){
if(isset($data['address']) && $data['address'] != ''){ // test d'ajout de l'addresse
$this->aauth->set_user_var('address', $data['address'], $user_id);
}
$this->load->view('confirmation_view',$data);
}else{
echo $this->aauth->print_errors();
$this->load->view('inscription_view',$data);
}
}else{
// Le formulaire est invalide
$data['signup'] = 1;
$this->load->view('inscription_view',$data); //inscription_view
}
}
set_user_var
works only without an user_id
if you logged in.
I will give you a feedback tomorrow morning, i cant anymore today :s but i didnt noticed than the function create_user return an id, so i guess its ok if you want me to close the issue now :)
Hi, i have errors and the address go on my DB :)
But I have a cosmetic probleme, and i think it's due to thetype of the variable.
if($user_id){
if(isset($address) && $address != ''){ // test d'ajout de l'addresse
$this->aauth->set_user_var('address', $address, $user_id);
}
$this->load->view('confirmation_view',$data);
}else{
$data['errors'] = $this->aauth->print_errors();
$this->load->view('inscription_view',$data);
}
View:
<?php
if(isset($errors)){
?>
<div class="inscription_error">
Errors: <?php echo $errors; ?>
</div>
<?php
}
?>
1) if(isset($errors)) my
<div class="inscription_error">
Errors: <?php echo $errors; ?>
</div>
try to change if(isset($errors)){
with if(isset($errors) && !empty($errors)){
doesn't work :s
I can't show you my view, it bugs, but even if we found how to display the div block, the error message will be in the top left of the page, is there any better way to show error to the user?
EDIT:
I changed the error text and putted a <div class="">
on it, it work for the design :D I just only don't know why if(isset($errors)){ with if(isset($errors) && !empty($errors)){
dont work but i can do an other way for this problem :)
you try a fail creation right? does it transfer the errors to the view?
Yep, i tried a fail connection (already exist name & email), and i "echo" the error only on the view, and i see them (on the top left of the page in place of in my div ^^ ).
EDIT:
Screen of what happend. The "errors" bloc under "signup" is display because i deleted the condition, else he didn't come. http://imgur.com/ZRidDPW
your div should work normal if you took it around the error.
you can use less <?php ?>
-tags too like this
<?php
if(isset($errors)){
echo '<div class="inscription_error">';
echo 'Errors: '.$errors;
echo '</div>';
}
?>
Ok, but still the problem.
Are you sure the print_errors can be designed? Perhaps he is like an echo and will always go to the top left of the page.
u can place a echo
any where, if you echo a div around its inside a div.
if its stuck on the top left check your css, for problems like this you can inspect really good it with a Browser Dev tool like firebug or check the html source code trough your browser
That's why i already do with chrome, and the div are juste under the body
what around the body? can you send me your view file? i think u have a failure in it.
How can i? When i put here, it bugs ^^'
zip it ^^
or change the extension from php to phps
it's zip but anyway: Unfortunately, we don’t support that file type. Sélect. fichiers Try again with a PNG, GIF, JPG, DOCX, PPTX, XLSX, TXT, PDF, or ZIP. ........
ok then put the view content in a ``` ^^
`<!DOCTYPE html>
it breaks
take it in a Quoting code ```
` is only for inline :D
i'm not very good at english so i don't really understand :D
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="Une description de la page" />
<meta name="keywords" content="a definir !!!!!!!!!!!!" />
<title></title>
<!-- Bootstrap -->
<link href="<?php echo base_url('bootstrap/css/bootstrap.min.css'); ?>" rel="stylesheet">
<link href="<?php echo base_url('bootstrap/css/main.css'); ?>" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">
</div>
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">
<div class="inscription_container">
<h3>Sign Up</h3>
<hr>
<?php
if(isset($again) && $again == 1){
echo '<div class="inscription_error">';
echo 'Errors: '.$errors;
echo '</div>';
}
?>
<form action="http://localhost/codeigniter-3.0.6/index.php/login/create_user" method="post">
<?php echo form_error('nickname'); ?>
<span class="inscription_label"><label for="nickname">Nickname:*</label></span>
<span class="inscription_input"><input type="text" name="nickname" value="<?php echo set_value('pseudo'); ?>"></span><br>
<?php echo form_error('password'); ?>
<span class="inscription_label"><label for="password">Password:*</label></span>
<span class="inscription_input"><input type="password" name="password" value="<?php echo set_value('pseudo'); ?>"></span><br>
<?php echo form_error('email'); ?>
<span class="inscription_label"><label for="email">E-mail:*</label></span>
<span class="inscription_input"><input type="text" name="email"></span><br>
<?php echo form_error('address'); ?>
<span class="inscription_label"><label for="address">Country:</label></span>
<span class="inscription_input"><input type="text" name="address"></span><br>
<span class="inscription_required">* Required Field</span>
<input type="submit" value="Send" value="<?php echo set_value('pseudo'); ?>">
</form>
</div>
</div>
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="<?php echo base_url('bootstrap/js/bootstrap.min.js'); ?>"></script>
</body>
</html>
in this view is the div around your body?
You have all the view, so error is in <div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">
who is in <div class="inscription_container">
who is in <div class="row">
who is in <body>
.
yes and the div goes where?
just under the <body>
under the <body>
?
yep
curious it should placed around the error
ho, i just saw that, meta are under error Oo
really strange ^^
which php version you use?
5.5.34
Ho, i think i have a start of answer:
$data['errors'] = $this->aauth->print_errors();
this print automaticaly the errors, even if we just wanted to put the errors in the $data ><
EDIT:
But so, i don't know how to put errors in variable without printing them in the controller :(
ah yeah that i haven't seen it ^^
you could use the print_errors()
without an echo because it echo's from it self (inside the function).
a other way is get_errors_array()
in controller instead print_errors()
, but then you need a foreach in your view
that was my failure :sweat_smile: ^^
i doesn't use the CI View files, i use a real template engine (twig) codeigniter-twiggy. its a lot easier to change the layout (not need to change every view :D)
Hi again !
I don't really understand how to display errors. For example, I have a sign up system, when the username or email is already taken it doesn't go on the DB, but i have to do errors message system myself, and i want to use your because it seems simplier.
What i tried is:
echo $data['errors'] = $this->aauth->print_errors($divider = '<br />');
but no success :/