codeigniter using ion auth, need to make input text fields longer - codeigniter

just installed ion auth for codeigniter and im customizing the login page.
the default login.php uses:
<?php echo lang('login_password_label', 'password');?>
<?php echo form_input($password);?>
which produces the following html results;
<label for="password">Password:</label><input type="password" name="password" value="" id="password" />
i need to append size="55" to the input box, so it looks like this:
<label for="password">Password:</label><input type="password" size="55" name="password" value="" id="password" />
any ideas how i would do that?

$password = array(
'name' => 'password',
'id' => 'password',
'size' => '55',
);
echo form_password($password);

Related

Laravel : How to create custom Register

I have 2 register and login form. The one is used to user and others is used to admin role.
In user role, I using from laravel authentication, is good and work well.
But, the problem is when I create custom register from admin role, its can't work well.
It can't store to database, when I check using echo function, it's not print anything just refresh the page.
Could you help me, what is wrong ???
this is my route
Route::get('/adminregister', 'Auth\LoginController#formreg')->name('admin-reg');
this is my controller
namespace App\Http\Controllers\Admin\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
class AregisterController extends Controller
{
use RegistersUsers;
public function __construct()
{
// $this->middleware('guest');
}
public function create(Request $request)
{
$this->validate(request(),[
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
if ($request('confirmpassword') == $request('password')){
$user = User::create(request(['name','email' ,'password','is_admin' => True, ]));
// return redirect()->route('admin-login')->with('status', 'Successfully create account');;
}
else {
return redirect()->route('admin-reg')->with('status', 'Confirm Password not match');;
}
}
}
In this controller, fisrt I want to check the password will confirmation password then store it to database.
this is my view page
<form action ="{{ route('user-create') }}" method="POST" enctype="multipart/form-data" >
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<div class="row mb-3">
<div class="col-md-12">
<div class="form-floating mb-2 mb-md-0">
<input class="form-control" id="inputFirstName" type="text" placeholder="Enter your first name" name="name" />
<label for="inputFirstName">Name </label>
</div>
</div>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="inputEmail" type="email" placeholder="name#example.com" name="email"/>
<label for="inputEmail">Email address</label>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputPassword" type="password" placeholder="Create a password" name="password" />
<label for="inputPassword">Password</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputPasswordConfirm" type="password" placeholder="Confirm password" name="confirmpassword" />
<label for="inputPasswordConfirm">Confirm Password</label>
</div>
</div>
</div>
<div class="mt-4 mb-0">
<div class="d-grid"><button type="submit" class="btn btn-primary">Create account</button></div>
</div>
</form>
Do you have any suggestion of how to fix it? It cant store anything in database, and when I check it using " echo " there is nothing :)
Thank you
The confirmed rule is looking for a field name {field}_confirmation. So if you are trying to confirm the 'password' input it would be looking for a field named password_confirmation. So that input in the form needs to be changed to the name password_confirmation.
You won't need to compare the 2 password fields that are submitted since the confirmed rule has done that for you already (that is what it is for; to confirm that they match).
The Request class is not callable, $request(...). That will throw an error since it isn't callable (there is no __invoke method defined on it to make it callable).
To create the User you can get the fields you need easily with the only method:
$request->only('name', 'email', 'password')
You can add your is_admin value to the array returned from the only call:
User::create($request->only('name', 'email', 'password') + ['is_admin' => true])
You will have to make sure that the is_admin field is "fillable" on the Model.
In general you don't need to be calling request() any where in this method since you have a Request instance injected as $request already.
Also, your form isn't handling a file upload so you don't need enctype="multipart/form-data".

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'email' cannot be null

i have 1 form and i want to insert it in 2 table
this is my form
<form action="{{route('dealers.store')}}" method="post">
#csrf
<input class="text email" type="text" name="name" placeholder="Full Name" required="">
<input class="text email" type="text" name="name_of_firm" placeholder="Firm Name" required="">
<input class="text email" type="text" name="number" placeholder="Mobile Number" required="">
<input class="text email" type="text" name="address" placeholder="Address" required="">
<input class="text email" type="email" name="email" placeholder="Email" required="">
<input class="text" type="password" name="password" placeholder="Password" required="">
<input class="text w3lpass" type="password" name="password" placeholder="Confirm Password" required="">
{{-- <div class="wthree-text">
<label class="anim">
<input type="checkbox" class="checkbox" required="">
<span>I Agree To The Terms & Conditions</span>
</label>
<div class="clear"> </div>
</div> --}}
<input type="submit" value="Submit" name="submit">
</form>
this is my DealerController store function where i seperate the data to insert in 2 different table
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'email' => 'required',
'password' => 'required',
'name_of_firm' => 'required',
'address' => 'required',
'number' => 'required',
]);
$user = User::create([
'name' => $request->input('name'),
'email' => $request->input('price'),
'password' => $request->input('detail'),
]);
$dealer = Dealer::create([
'name_of_firm' => $request->input('name_of_firm'),
'address' => $request->input('address'),
'number' => $request->input('number'),
]);
return redirect()->route('admin/charts')->withSuccess('Done');
}
this is my Dealer model where is a relation with user table
use HasFactory;
protected $table = 'dealers';
public function user() {
return $this->belongsTo(User::class);
}
and this is my User model it is package of jetstream
public function dealer() {
return $this->hasMany(Dealer::class);
}
In your controller you're saving the info from the User like this:
$user = User::create([
'name' => $request->input('name'),
'email' => $request->input('price'),
'password' => $request->input('detail'),
]);
But there is a request there that makes no sense. In the email you are trying to save the info from an input with the name "PRICE", but that input doesn't exist on your form. The same case applies to the password. That's the source of the error, your are tying to save a null value (since price doesn't exist on the request) to the email column. Try this:
use Illuminate\Support\Facades\Hash;
[....]
$user = User::create([
'name' => $request->input('name'),
'email' => $request->input('email'),
'password' => Hash::make($request->input('password')),
]);
Note how on the password I added Hash. This encrypts the password to store it securely on your database. If you want to just save the text without that type of security refrain from using Hash.

redirect to section of one-page site in laravel not working

I am working on a site in laravel. The email sending form is at the footer of the website. When I send an image, for now it just saves the email in the database. After saving the email, I want to redirect to the footer section of the one-page website but it doesn't. Funny thing is, it works right when validation is removed.
here is my form:
<form class="form" method="POST" action="{{ action('IndexController#email') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="name" class="form-control">
<input type="email" name="email" class="form-control">
<input type="text" name="subject" class="form-control">
<textarea class="form-control" name="message" style="height: 100px;"></textarea>
<button type="submit" class="btn btn-primary btn-block">Send</button>
</form>
Here is the post route:
Route::post('new/sendemail', ['as' => 'sendemail', 'uses' => 'IndexController#email']);
and here is the controller method:
public function email(Request $request){
$this->validate($request, [
'name' => 'required',
'email' => 'required',
'subject'=>'required',
'message' => 'required'
]);
$input = $request->all();
Email::create($input);
return redirect('new/#contact'); //this is where i want to redirect to that section but it doesn't work
}

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 Form Validation for several input type text

I have group of text boxes like below
<input type="text" size="10" value="<?php echo set_value('sizes[]'); ?>" name="sizes[]"/>
<input type="text" size="10" value="<?php echo set_value('sizes[]'); ?>" name="sizes[]"/>
<input type="text" size="10" value="<?php echo set_value('sizes[]'); ?>" name="sizes[]"/>
<input type="text" size="10" value="<?php echo set_value('sizes[]'); ?>" name="sizes[]"/>
<input type="text" size="10" value="<?php echo set_value('sizes[]'); ?>" name="sizes[]"/>
then if I set validation rules like below
array(
'field' => 'sizes[]',
'label' => 'SIZES',
'rules' => 'required|xss_clean'
),
then codeigniter check every input box for value. If every text box is filled up then codeigniter returns true. But I want to get if anyone of them filled up then return true
How can I do that??
Thanks
You can create a custom validation function in your controller and implement your own check on the input. First, you add a new function to the controller:
function _is_valid($str, $field_name)
{
//First we see if the field name we are checking has multiple values
if (!is_array($this->input->post($field_name)))
return false;
//Let's get the posted values and see if any of them has a value:
foreach ($this->input->post($field_name) as $value)
if (strlen($value)) return true;
//If we get here that means there was no value posted:
return false;
}
Next, change your rules for the field:
'rules' => 'required|xss_clean'
To:
'rules' => 'callback__is_valid[sizes]|xss_clean'
You can read more about custom validation functions here:
[http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks][1]

Resources