I have a search module in a page made with codeigniter. The search goes off automatically just after the first entry. How can i trigger the search after the user stop key in ?
<?php
$attributes = array("class" => "form-horizontal", "id" => "search", "name" => "search");
echo form_open("secret_cont/search", $attributes);?>
<input type="text" name="search" placeholder="Search a student by name" id="search" oninput="document.forms.search.submit();"/>
<input type='submit' value='Ok' />
<?=form_close();?>
Thanks !
Related
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".
I have two forms as below
Form 1
<form id="form1" action="loc1" method="post">
<div class="form-group">
<label for="exampleDOB">Date of Brth:</label>
<input type="text" class="form-control" id="dob" name="dob" placeholder="Date of Birth"
value="{{$tuser->DOB ?? ''}}" >
<div class="error text-danger"></div>
</div>
<button type="submit">Next Step</button><br><br>
<button type="button">Previous </button>
</form>
Form 2
<form id="form2" action="loc2" method="post">
<div class="form-group">
<label for="exampleMob">Mobile Number:</label>
<input type="text" class="form-control" id="mobno" name="mobno" placeholder="Valid Mobile
Number" value="{{$tuser->mobno ?? ''}}" >
<div class="error text-danger"></div>
</div>
<button type="submit">Final Step</button><br><br>
<button type="button">Previous </button>
</form>
$tuser is an object containing all the data for that user, from the database
When users click on Next Step in Form 1, the data is stored in database and the user is directed to Form 2.
But the problem is- on clicking the Previous button, I am losing all the pre-filled data in the Previous form. How can I retain form data (to be shown in the input fields as available in the database)?
if you have saved them in DB, so you can retrieve all of it using an id and store it in session like:
session->put("form_1_id",$DBInsertedId);
in form 1 you can check if there are any results, you can retrieve it like:
if(session->has("form_1_id"))
return view('form_1',['filled_data' => Model::find(session->get("form_1_id")) ]);
and in the view you can check for parameter existence form_1_id like you did:
<input type="text" class="form-control" id="dob" name="dob" placeholder="Date of Birth"
value="{{$filled_data->DOB ?? ''}}" >
just add a filled name id in your input view and fill it if form has been filled out before. since doing this can assure you that the filled form will be updated if there was a record for it before:
<input type="hidden" id="id" name="id" value="{{$filled_data->id ?? ''}}" >
and in your controller:
Model::insertOrUpdate(['id' => $request->id ], ... );
UPDATE:
insertOrUpdate Equivalent in psudo-code :
if(DB::exist(['id' => $request->id]))
update(['id' => $request->id , ... ]);
else
insert([ ... ]);
All of the other request in my view is included already in the request using
dd($request), but my radio button input is cannot be read by request.
attached here is my code
View
<form method="post" action="{{route('update-dependent')}}">
<div class="form-group">
{{csrf_field()}}
<div class="form-group">
<label>Last Name</label>
<input type="text" name="lname" value="{{$dependent->lname}}" class="form-control">
</div>
<div class="form-group">
{{-- conditional statement to check what geneder --}}
<input type="hidden" name="gender" value="bading" class="form-control">
<label>Male</label>
<input type="radio" name="gender" value="male" class="form-control">
<label>Female</label>
<input type="radio" name="gender" value="female" class="form-control">
</div>
<div class="form-group">
<label>Relationship</label>
<input type="text" name="relationship" value="{{$dependent->relationship}}" class="form-control">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</form>
Controller
HMO::UpdateDependent($request);
return redirect()->route('edit', request('hmo_id'));
Model
public static function updateDependent($request)
{
DB::table('hmos_detail')
->where('id', $request->get('dependent_id'))
->update([ 'lname' => $request->get('lname'),
'gender' => $request->get('gender'),
'relationship' => $request->get('relationship'),
return true;
}
result
array:2 [▼
"_token" => "sP9FVEbL3pI5Yaf2jlSfDATNtOTSz2Rheb4bH9Ti"
"lname" => "test"
"relationship" => "WIFE"
]
First of all if you want value of radio then make sure you have proper validation in place.
If you don't know how to validate then have a look at following link
https://laravel.com/docs/5.5/validation#validation-quickstart
Furthermore
If you want some default value for radio button then make sure you have a hidden field that will have default value is this case you dont need validation.
So the basic example would be
<input type="hidden" name="gender" value="bading" class="form-control">
The radio btn will always have bading as default weather its selected or not. But If you add
<input type="radio" name="gender" value="male" class="form-control">
<input type="radio" name="gender" value="female" class="form-control">
Then the hidden field is replaced with the selected value.
As #Sree mentioned, You need to give gender to the fillable.
protected $fillable = ['gender', ....];
As from the documentation :
Mass Assignment You may also use the create method to save a new model
in a single line. The inserted model instance will be returned to you
from the method. However, before doing so, you will need to specify
either a fillable or guarded attribute on the model, as all Eloquent
models protect against mass-assignment by default.
It might be because you forgot to add gender in your Mass Assignment. In your model add,
protected $fillable = ['gender', ....];
I have followed the doc. I created two tables:
countries
country_translations.
Now I changed the column name => key and value cause I can get the value (lang text) by query key.
Say for example :
$r = 'DE';//App::getLocale(); // 'fr'
$germany = Country::where('code', $r)->first();
// I want to get value where key= 'contacts-last-name'
$translation = $germany->translate($r, true)->where('key', 'contacts-last-name')->value;
print_r($translation);
exit("----");
I get:
ERROR: Undefined property
How may I get specific value using new query/sub query (key).
For an Example here is my method and view
Updated the method as below ::
$translation = $germany->translate($r, true)->where('key', 'contacts-last-name')->first();
echo "<pre>"; print_r($translation->toArray()); exit("----");
and got the answer:
Array
(
[id] => 1
[country_id] => 83
[key] => contacts-last-name
[value] => Achternaam
[locale] => DE
)
In view Page I have a form :
<label class="col-sm-2 control-label">{{trans('labels.contacts-first-name')}}</label>
<div class="col-sm-4">
<input name="first_name" id="first_name" type="text" class="form-control" required disabled>
</div>
<label class="col-sm-2 control-label">{{trans('labels.contacts-last-name')}}</label>
<div class="col-sm-4">
<input type="text" id="last_name" name="last_name" class="form-control" disabled>
</div>
for this one I have a question how may I pass translate data and make transable views all the time {{trans('labels.contacts-last-name')}}
You can access it like so:
$translation = $germany->{'contacts-last-name:'.$r};
https://github.com/dimsav/laravel-translatable/blob/master/src/Translatable/Translatable.php#L153
After
echo "<pre>"; print_r($translation->toArray()); exit("----");
Result:
Array
(
[id] => 1
[country_id] => 83
[key] => contacts-last-name
[value] => Achternaam
[locale] => DE
)
change your this line
$translation = $germany->translate($r, true)->where('key', 'contacts-last-name')->value;
to this, and then try it
$translation = $germany->translate($r, true)->where('key', 'contacts-last-name')->get();
print_r($translation);
exit("----");
Updated
in your view, {{trans('labels.contacts-last-name')}} this way means that you are trying to grab translation from your lang directory exists in your project, in actual this is manual file based/array (key/pair) way.
while you want Dynamic/DB based, you can do this
pass you $translation variable into your view, eg
return view('form-view', compact('translation'));
and then in your view you can do this.
<label class="col-sm-2 control-label">{{$translation[0]->value}}</label>
<div class="col-sm-4">
<input name="first_name" id="first_name" type="text" class="form-control" required disabled>
</div>
<label class="col-sm-2 control-label">{{$translation[1]->value}}</label>
<div class="col-sm-4">
<input type="text" id="last_name" name="last_name" class="form-control" disabled>
</div>
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' );