what am I doing wrong with form_validation messages name field access? - codeigniter

I want to try to valid confirm password matches with my confirm password, but it not then it will show me an error , but when I try to set up my messages for username then show me it cannot be accessed by it what am I doing wrong? but I try to change name filed in my username , but it doesn't work.
new_user controller
public function new_user(){
$first_name = $this->security->xss_clean(strip_tags($this->input->post('first_name')));
$last_name = $this->security->xss_clean(strip_tags($this->input->post('last_name')));
$profile_id = $this->security->xss_clean(strip_tags($this->input->post('profile_id')));
$password = $this->security->xss_clean(strip_tags($this->input->post('password')));
$username = $this->security->xss_clean(strip_tags($this->input->post('username')));
$data = array(
'first_name' => $first_name,
'last_name' => $last_name,
'profile_id' => $profile_id,
'password' => password_hash($password, PASSWORD_BCRYPT),
'username' => $username,
);
$this->form_validation->set_rules('first_name','first_name','trim|required');
$this->form_validation->set_rules('last_name','last_name','trim|required');
$this->form_validation->set_rules('username','username','trim|required|');
$this->form_validation->set_rules('password', 'password', 'trim|required');
$this->form_validation->set_rules('conf_password', 'conf_password', 'matches[password]|required');
$this->form_validation->set_message('first_name', 'Please enter First Name');
$this->form_validation->set_message('last_name', 'Please enter Last Name');
$this->form_validation->set_message('username', 'Please enter Username');
$this->form_validation->set_message('password', 'Please enter Password');
if ($this->form_validation->run() == FALSE) {
$this->json($this->form_validation->error_array());
}else{
$this->user->signup($data);
}
}
form
<form id="signup" method="post" onsubmit="return false;">
<h2 class="sr-only">New User</h2>
<div class="illustration">
<i class="icon ion-ios-locked-outline" style="color: rgb(251, 244, 244);"></i>
</div>
<div class="form-group">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="form-control"
required="required" />
</div>
<div class="form-group">
<input type="text" name="last_name" id="last_name" placeholder="Last Name" class="form-control"
required="required" />
</div>
<div class="form-group">
<select name="profile_id" id="profile_id" class="form-control" required="required">
<option value="">Select a Profile</option>
<?php foreach ($profile as $value): ?>
<option value="<?php echo $value['id'];?>">
<?php echo $value['profile']; ?>
</option>
<?php endforeach ?>
</select>
</div>
<div class="form-group">
<input type="text" name="username" id="username" placeholder="username" class="form-control"
required="required" />
</div>
<div class="form-group">
<input type="password" name="password" id="password" placeholder="***********" class="form-control"
required="required" />
</div>
<div class="form-group">
<input type="password" name="conf_password" id="conf_password" placeholder="***********" class="form-control"
required="required" />
</div>
<div class="form-group">
<button class="btn btn-primary btn-block" type="submit" style="background-color: rgb(41, 54, 78);">Ingresar</button>
</div>
</form>
output error
{username: "Unable to access an error message corresponding to your field name username.()"}
username
:
"Unable to access an error message corresponding to your field name username.()"

I think you should
Replace this
$this->form_validation->set_rules('username','username','trim|required|');
To:
$this->form_validation->set_rules('username','username','trim|required');

Related

Insert data from modal, Codeigniter

I'm trying to insert the input data from a modal but I don't know how to achieve this. I'm not really familiar with AJAX(I apologize for that). I did some readings and research but I'm getting confused. Here is my modal content reserve_form.php
<form action="" id="book-form">
<div class="row flex-lg-row-reverse align-items-center pt-1">
<h3>Reservation Details</h3>
<div class="col-10 col-sm-8 col-lg-6">
<input type="hidden" name="package_id" value="<?php ?>">
<div class="form-group">
<label for="date_start" class="control-label">Reserve Date:</label>
<input type="date" name="date_start" id="date_start" class="form-control form-conrtrol-sm rounded-0" min="<?php echo date("Y-m-d") ?>" value="<?php echo date("Y-m-d") ?>" required>
</div>
<div id="msg" class="text-danger"></div>
<div id="check-availability-loader" class="d-none">
<center>
<div class="d-flex align-items-center col-md-6">
<strong>Checking Availability...</strong>
<div class="spinner-border ml-auto" role="status" aria-hidden="true"></div>
</div>
</center>
</div>
<div class="form-group">
<label for="quantity" class="control-label">Number of Person <span><i>(Max. of 15 person)</i></span></label>
<input type="number" class="form-control form" required name="person" value="">
</div>
<div class="form-group">
<label for="amount" class="control-label">Additional Inclusions</label>
<div>
<input type="checkbox" id="inclusion" name="inclusion" value="">
<label for="inclusion"> Unlimited Samgyupsal & Al Fresco dining experience</label>
</div>
</div>
<div class="form-group">
<label for="amount" class="control-label">Total Amount</label>
<input type="number" name="cost" id="amount" class="form-control form-conrtrol-sm rounded-0 text-right" value="<?php echo isset($cost) ? number_format($cost, 2) : 0.00 ?>" required readonly>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="name" class="control-label">First Name</label>
<input type="text" class="form-control mb-3" name="firstname" placeholder="Enter First Name" value="">
</div>
<div class="form-group">
<label for="name" class="control-label">Last Name</label>
<input type="text" class="form-control mb-3" name="lastname" placeholder="Enter Last Name" value="">
</div>
<div class="form-group">
<label for="name" class="control-label">Contact</label>
<input type="text" class="form-control mb-3" name="contact" placeholder="09xx-xxx-xxxx" value="">
</div>
<div class="form-group">
<label for="name" class="control-label">Email</label>
<input type="text" class="form-control mb-3" name="email" placeholder="example#email.com" value="">
</div>
</div>
</div>
<div class="modal-footer py-2">
<button class="btn btn-warning" type="submit" name="details">Save</button>
<button class="btn btn-secondary "><span class="close-sm">Close</span></button>
</div>
</form>
Here's my modal in view.php
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header py-1">
<h3><?php echo $packages->title; ?></h3>
</div>
<div class="modal-body py-2">
<?php $this->load->view('forms/reserve_form'); ?>
</div>
</div>
Here' my Controller(page.php)
public function reservation_details()
{
$details = array();
$details2 = array();
if ($this->input->post('details')) {
$this->form_validation->set_rules('firstname', 'First Name', 'required');
$this->form_validation->set_rules('lastname', 'Last Name', 'required');
$this->form_validation->set_rules('contact', 'Contact', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('date_start', 'Reserve Date', 'required');
$this->form_validation->set_rules('person', 'Number of Person', 'required|max_length[15]');
if ($this->form_validation->run() == true) {
$details = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'contact' => $this->input->post('contact'),
'email' => $this->input->post('email'),
);
$this->UI_model->reserve_details($details);
$details2 = array(
'date_start' => $this->input->post('date_start'),
'person' => $this->input->post('person'),
'inclusion' => $this->input->post('inclusion'),
);
$this->UI_model->reserve_add($details2);
}
}
}
Here's the Model
public function reserve_details(){
if (!empty($data)) {
$this->db->insert('clients', $data);
return $this->db->insert_id();
}
return false;
}
public function reserve_add(){
if (!empty($data)) {
$this->db->insert('book_list', $data);
return $this->db->insert_id();
}
return false;
}
Also, I'm trying to insert the data for multiple tables. Any help will be much appreciated. Thanks! Is is also fine to place the submit button at modal footer? or it should be at reserve.php?
You're passing data array through these functions.
$this->UI_model->reserve_details($details);
$this->UI_model->reserve_add($details2);
But in the model, you're not catching those.
public function reserve_details(){
public function reserve_add(){
So it should be
public function reserve_details($data){
public function reserve_add($data){
Since you're checking if (!empty($data)) { its always retuns false, unless Undefixed Varibale error.

How can I color input fields border red when I get validation error laravel 5.3

My Validation Controller:
public function store(Request $request)
{
// dd($request->all());
/////Validations////
$this->Validate($request, [
'name' => 'required|min:3|',
'email' => 'required|unique:customers' ,
'favorite' => 'required',
'Password' => 'required|min:6',
'Confirm_Password' => 'required|same:Password',
]);
$user = new customer;
$user ->name=input::get("name");
$user ->email=input::get("email");
$user ->country=input::get("country");
$user ->gender=input::get("gender");
$user ->favorite=implode(" , " , input::get("favorite"));
if(input::hasfile("image")){
$files = Input::file('image');
$name = time()."_". $files->getClientOriginalName();
$image = $files->move(public_path().'/image' , $name);
$user->image=$name;
}
$user ->psw=input::get("psw");
$user->save();
return redirect("showall");
}
Insert.blade.php
<form action="store" method="post" enctype="multipart/form-data">
<ul><span style="color:red;">{!! $errors->first('name') !!}</span></ul>
<label for="name">Name</label>
<input type="text" name="name" value="{{old('name')}}" id="name" autofill="off">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<ul><span style="color:red;">{!! $errors->first('email') !!}</span></ul>
<label for="email">Email</label>
<input type="email" name="email" value="{{old('email')}}" id="email" autofill="off">
<br>
<br>
Country <select name="country" id="country">
<option value="USA">USA </option>
<option value="ENGLAND">ENGLAND </option>
<option value="JAPAN">JAPAN </option>
<option value="ITALY">ITALY</option>
</select>
<br>
<br>
Gender <input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
<br>
<br>
<ul><span style="color:red;">{!! $errors->first('favorite') !!}</span></ul>
<input type="checkbox" name="favorite[]" value="sout">South
<input type="checkbox" name="favorite[]" value="north">North
<input type="checkbox" name="favorite[]" value="east">East
<input type="checkbox" name="favorite[]" value="west">West
<br>
<br>
<input type="file" name="image">
<br>
<br>
<ul><span style="color:red;">{!! $errors->first('Confirm_Password') !!}</span></ul>
<label for="email">Password</label>
<input type="password" name="Password" value="" id="Password">
<ul><span style="color:red;">{!! $errors->first('Confirm_Password') !!}</span></ul>
<label for="email">Confirm Password</label>
<input type="Password" name="Confirm_Password" value="" id="cpsw">
<br>
<br>
<label for="submit"></label>
<input type="submit" name="submit" value="submit" id="submit">
</form>
Form where I want to change fields color:
I want to change input fields border color to change red when I get a validation error.
I try my best but I don't know how to rid off this problem.
Add this CSS code first:
.form-error {
border: 2px solid #e74c3c;
}
And HTML Code is ::
<input type="text" class="form-control{{($errors->first('name') ? " form-error" : "")}}" name="name" placeholder="Name">
if you need error message below the input field then ::
<input class="form-control" required="required" name="name" type="text" id="name">
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}

Octobercms successful mail send returns empty alert

I am a newbie to Laravel and OctoberCMS.
I have successfully set up an info request form that sends me an email via Mailgun when submitted. Submission is handled by an AJAX handler.
The problem I have is that the process opens an alert box with an empty array on the form page.
Here is the page: http://imageweaversmarketing.com/
Click on 'CONTACT' in the top-right to move to the form.
Here is the partial with the form:
<div class="row">
<div class="col-lg-12">
<form data-request="onInfoRequest" name="sentMessage" id="contactForm" novalidate="">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required="" data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required="" data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required="" data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required="" data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl">
Send Message
</button>
</div>
</div>
</form>
</div>
Here is the PHP AJAX:
use Illuminate\Support\Facades\Mail;
public function onInfoRequest() {
$data = ['name' => 'test from function'];
Mail::send('mail.inforequest', $data, function ($message) {
$message->to('fake#hidden.com', 'Roger Creasy');
});
}
I appreciate any help.
I see you haven't used the data-request-success handler. That's necessary to show the output when mail is successful. Here's how I do it
function onSend()
{
// Collect input
$name = post('name');
$email = post('email');
// Form Validation
$validator = Validator::make(
[
'name' => $name,
'email' => $email
],
[
'name' => 'required',
'email' => 'required|email'
]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form
$to = System\Models\MailSettings::get('sender_email');
$params = compact('name','email');
Mail::sendTo($to, 'temp.website::mail.newrequest', $params);
return true;
}
And on the form side I used
<form class="form-horizontal" data-request="onSend" data-request-success="alert('We have recieved your email.. we\'ll get back to you shortly')">
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-5">
<input id="name" name="name" type="text" placeholder="Name" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-5">
<input id="email" name="email" type="text" placeholder="Email ID" class="form-control input-md" required="">
</div>
</div>
</form>
So basically all you need is to add a data-request-success for it to work. Enjoy!
I had to get this completed. So, I gave up on a solution within October.
I am posting what I did as a workaround, in case it is helpful to someone else.
What I did is create a route resource, and direct it to a controller to handle the form. basically I went to the Laravel base structure and handled the form through its MVC.

wordpress doing register but login with the same credentials not working

I have created a register form in wordpress and doing register in ajax.
The form is like this
<form id="user-register-form" method="" action="" novalidate="novalidate">
<div class="full-column-width">
<div class="half-column-width">
<input type="text" name="firstname" placeholder="First Name" id="firstname" required="" aria-required="true">
</div>
<div class="half-column-width">
<input type="text" name="lastname" placeholder="Last Name" id="lastname" required="" aria-required="true">
</div>
</div>
<div class="full-column-width">
<input type="email" name="email" placeholder="E-mail" id="email" required="" aria-required="true">
</div>
<div class="full-column-width">
<input type="number" name="phone" placeholder="Phone" id="phone" required="" aria-required="true">
</div>
<div class="full-column-width">
<input type="password" name="password" placeholder="Password" id="password" required="" aria-required="true">
</div>
<div class="full-column-width">
<input class="submit" type="submit" name="submit" id="user_get_register" value="Register">
</div>
</form>
in the functions file I have made my function like this
function user_register() {
$data = $_POST['data'];
parse_str($data, $arr);
$userdata = array (
'user_login' => $arr['email'],
'firstname' => $arr['firstname'],
'lastname' => $arr['lastname'],
'email' => $arr['email'],
'phone' => $arr['phone'],
'password' => $arr['password'],
);
//check username exists
if( username_exists( $arr['email'] ) ) {
echo 'username exists';
}
else {
$id = wp_insert_user($userdata);
if( !is_wp_error( $id )) {
wp_set_current_user($id);
wp_set_auth_cookie($id);
echo 'user created';
}
}
exit;
}
add_action('wp_ajax_nopriv_user_register', 'user_register');
It is doing register the user with its details but when I am doing the same details for login from the wordpress admin login its not working. I have checked the database. The values are there. Everytime when I am doing login to the dashboard it is showing
ERROR: The password you entered for the username test#name.com is incorrect.
Can someone tell me why this error? and how to solve this?
you have a mistake in user data, change password to user_pass
$userdata = array (
'user_login' => $arr['email'],
'firstname' => $arr['firstname'],
'lastname' => $arr['lastname'],
//'email' => $arr['email'], ---- cant store this with this function
//'phone' => $arr['phone'], --- cant store this with this function
'user_pass' => $arr['password'],
);
Also you are passing in keys that dont exist for wp_insert_user(), you need to save these as usermeta =
update_user_meta( $id, '_telephone', '555-555' );

codeigniter submit ajax alert success

i have this form that submits personal details
here is my view
<?php $attributes=a rray( 'autocomplete'=>"off", 'id' => 'theForm');?>
<?php echo form_open_multipart( 'employee/personaldetails', $attributes); ?>
<div class="row">
<div class="span3 offset1">
<label>First Name</label>
<input onkeypress="return fnAllowAlpha(event);" maxlength="50" type="text" value="<?php echo $info['first_name']; ?>" name="first_name" disabled>
<input type="hidden" value="<?php echo $info['employee_image']; ?>" name="employee_image" disabled>
</div>
<div class="span3">
<label>Middle Name</label>
<input onkeypress="return fnAllowAlpha(event);" maxlength="50" type="text" value="<?php echo $info['middle_name']; ?>" name="middle_name" disabled>
</div>
<div class="span3">
<label>Last Name</label>
<input onkeypress="return fnAllowAlpha(event);" maxlength="50" type="text" value="<?php echo $info['last_name']; ?>" name="last_name" disabled>
</div>
<div class="span1">
<div class="down1">
<button type="submit" class="button-orange" id="btnSave" style="display:none;">Save</button>
</div>
</div>
CONTROLLER
$this->load->model('mdl_employee','emp');
$id = $this->session->userdata('id');
$P1 = $this->input->post('first_name');
$P2 = $this->input->post('middle_name');
$P3 = $this->input->post('last_name');
$this->emp->update_myinfo($id, $P1, $P2, $P3);
model
public function update_myinfo($id, $P1, $P2, $P3){
$employee_data = array(
'first_name' => $P1,
'middle_name' => $P2,
'last_name' => $P3);
$this->db->where('employee_id', $id);
$this->db->update('employee', $employee_data);
}
i dont know how to use ajax.
i want to alert the ajax if success or not. after updating my database.. im just new programmer
Maybe you could try googling since its so common to submit forms using ajax.
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
Submitting HTML form using Jquery AJAX
I would suggest first try these links..and if u still get stuck then let us know, we would surely help you :)

Resources