OpenCart 3 + Journal 3, remove email field from guest checkout? - php

I want to remove email field from checkout page for guest, I use OpenCart 3 with theme Journal 3. So what I can do?
I've tried to call out it from guest.php but still not work.

You can't just remove email field. A lot of system properties connected to email on checkout, although using journal3 makes more complicated extraction of email.
You can see what fields you can turn on / switch of in Journal Quick Checkout:
Journal > Skins > Checkout
UPDATED
To disable Email only for guests in Journal 3 Quick Checkout:
Go to /catalog/view/theme/journal3/template/journal3/checkout/register.twig
Find
{# customer email #}
<div class="form-group required account-email">
<label class="control-label" for="input-email">{{ entry_email }}</label>
<input v-model="order_data.email" type="text" name="email" value="" placeholder="{{ entry_email }}" id="input-email" class="form-control"/>
<span class="text-danger" v-if="error && error.email" v-html="error.email"></span>
</div>
Adding a check, like for password v-if="account === 'register'". New code is
{# customer email #}
<div v-if="account === 'register'" class="form-group required account-email">
<label class="control-label" for="input-email">{{ entry_email }}</label>
<input v-model="order_data.email" type="text" name="email" value="" placeholder="{{ entry_email }}" id="input-email" class="form-control"/>
<span class="text-danger" v-if="error && error.email" v-html="error.email"></span>
</div>
Now go to /catalog/controller/journal3/checkout.php and find
// email
if ((utf8_strlen(Arr::get($this->request->post, 'order_data.email')) > 96) || !filter_var(Arr::get($this->request->post, 'order_data.email'), FILTER_VALIDATE_EMAIL)) {
$error['email'] = $this->language->get('error_email');
} else if (($this->session->data['account'] === 'register') && $this->model_account_customer->getTotalCustomersByEmail(Arr::get($this->request->post, 'order_data.email'))) {
$error['email'] = $this->language->get('error_exists');
}
Replace with
// email
if ($this->session->data['account'] === 'register') {
if ((utf8_strlen(Arr::get($this->request->post, 'order_data.email')) > 96) || !filter_var(Arr::get($this->request->post, 'order_data.email'), FILTER_VALIDATE_EMAIL)) {
$error['email'] = $this->language->get('error_email');
} else if (($this->session->data['account'] === 'register') && $this->model_account_customer->getTotalCustomersByEmail(Arr::get($this->request->post, 'order_data.email'))) {
$error['email'] = $this->language->get('error_exists');
}
}

Additional to the emntioned 3 steps you have to fix the sendmail funtion. One way is mentioned here in 2 more steps:
File: system/library/mail.php
Change:
$this->to = $to;
To:
if ($to != '') {$this->to = $to;} else { $this->to = 'web-and-seo#itech.bg';}
Change web-and-seo#itech.bg to an e-mail that you will receive the confirmation instead of the customer.
Then remove the * from the mail field on checkout page
File: catalog/view/theme/journal3/template/journal3/checkout/register.twig
Change:
<div class="form-group required account-email">
To:
<div class="form-group account-email">
Good luck.

Related

My WordPress Custom Login Form can't login successfully

(Hi, I create a custom login form for my WordPress website. Actually, I create that form for wholesale customers, first, they need to register and add their tax number to the registration form, after finishing the registration form they can use the login form to buy the wholesale items. then customers need to enter their user name and tax number to log in to the wholesale page) This is the result I create a custom registration form and login form. but now my registration form working successfully but my login form not working on my live site. There is some error showing like this (Warning: Cannot modify header information - headers already sent by (output started at /home/customer/www/freshmartuk.co.uk/public_html/wp-content/themes/kadence/custom-login-page.php:26) in /home/customer/www/freshmartuk.co.uk/public_html/wp-includes/pluggable.php on line 1107) I try many time to solved this error but I can't , so I need some help to fix this error
<?php
/* Template Name: Custom Login Page */
get_header();
global $user_ID;
global $wpdb;
if (!$user_ID) {
if ($_POST) {
$username = $_POST['username'];
$taxnumber = $_POST['tax_number'];
$user = get_user_by('login', $username);
// sql part //
if (!is_wp_error($user)) {
global $wpdb;
$sql = "SELECT um.meta_value
FROM vmb_usermeta um
join vmb_users wu on um.user_id = wu.id where wu.user_login='$username' and um.meta_key='tax_number'";
$tax_results = $wpdb->get_results($sql);
if ($tax_results[0]->meta_value == $taxnumber) {
$user = get_user_by('login', $username);
// Redirect URL //
if (!is_wp_error($user)) {
wp_clear_auth_cookie();
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);
$redirect_to = header('Location: url');
// echo "login successfully";
wp_safe_redirect($redirect_to);
exit();
}
}
}
} else {
// user in logged out status
?>
<section id="custom-login-wholesale">
<div class="container custom-login-wholesale">
<div class="login-form">
<div class="whole-sale-title">
<h1>Whole Sale</h1>
</div>
<div class="wholesale-login">
<form class="login-fm" method="POST">
<div class="form-group">
<label for="uername" class="login-titls">User Name</label>
<input class="form-control" type="text" id="username" name="username" placeholder="Enter Username" required="required">
</div>
<div class="form-group">
<label for="Password" class="login-titls">Tax Number</label>
<input class="form-control" type="password" id="tax_number" name="tax_number" placeholder="Enter Tax Number" required="required">
</div>
<div class="form-group">
<button class="custom-login-btn" type="submit" name="btn_submit">Log In</button>
</div>
</form>
</div>
</div>
</div>
</section>
<?php
}
} else {
// user is logged in
}
get_footer();
?>
``
This is my DB table names
(vmb_usermeta
vmb_users)
`

How do I update records in a loop in Laravel 8

I am developing a student portal in Laravel 8. I would love to update the class subjects.
Here is my controller
public function UpdateAssignSubject(Request $request, $class_id)
{
if ($request->subject_id == null) {
$notification = [
'message' => 'Sorry You did not Select any Subject',
'alert-type' => 'error'
];
return redirect()->route('assign.subject.edit', $class_id)->with($notification);
} else {
$countClass = count($request->subject_id);
AssignSubject::where('class_id', $class_id)->delete();
for ($i = 0; $i < $countClass; $i++) {
$assign_subject = new AssignSubject();
$assign_subject->class_id = $request->class_id;
$assign_subject->subject_id = $request->subject_id[$i];
$assign_subject->full_mark = $request->full_mark[$i];
$assign_subject->pass_mark = $request->pass_mark[$i];
$assign_subject->subjective_mark = $request->subjective_mark[$i];
$assign_subject->save();
} // End For Loop
}// end Else
$notification = [
'message' => 'Assigned Subject Updated Successfully',
'alert-type' => 'success'
];
}
This very piece of code AssignSubject::where('class_id', $class_id)->delete(); is giving me issues since I am using the AssignSubject as a pivot table thus deleting the Id's produces errors in the long run.
Here is my view
#foreach($subjects as $subject)
<option value="{{ $subject->id }}" {{ ($edit->subject_id == $subject->id)? "selected": ""
}}>{{ $subject->name }}</option>
#endforeach
<div class="form-group">
<h5 style="color:black">Full Mark <span class="text-danger">*</span></h5>
<div class="controls">
<input type="text" name="full_mark[]" value="{{ $edit->full_mark }}" class="form-control"
style="background-color: rgb(176, 172, 216);color:black" >
</div>
<div class="col-md-2">
<div class="form-group">
<h5 style="color:black">Pass Mark <span class="text-danger">*</span></h5>
<div class="controls">
<input type="text" name="pass_mark[]" value="{{ $edit->pass_mark }}" class="form-control"
style="background-color: rgb(176, 172, 216);color:black">
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<h5 style="color:black">Subjective Mark <span class="text-danger">*</span></h5>
<div class="controls">
<input type="text" name="subjective_mark[]" value="{{ $edit->subjective_mark }}" class="form-
control" style="background-color: rgb(176, 172, 216);color:black">
</div>
</div>
</div>
Please how can I update the record without deleting first. Any help would be greatly appreciated.
Instead of deleting all entities, you can simply update them if they do exist.
In case they do not, you need to create a new one, like you did in your for loop.
I adjusted your code, to check if a subject already exists, if it does it updates it, otherwise a new one is created
$countClass = count($request->subject_id);
// remove this line
// AssignSubject::where('class_id', $class_id)->delete();
for ($i = 0; $i < $countClass; $i++) {
// a class can only have each subject 1 time, so you can filter for it
$entity = AssignSubject::where('class_id', $class_id)
->where('subject_id', $request->subject_id[$i])
->first();
// if entry does not exist, ->first() will return null, in this case, create a new entity
$assign_subject = $entity ?? new AssignSubject();
// update columns
$assign_subject->class_id = $request->class_id;
$assign_subject->subject_id = $request->subject_id[$i];
$assign_subject->full_mark = $request->full_mark[$i];
$assign_subject->pass_mark = $request->pass_mark[$i];
$assign_subject->subjective_mark = $request->subjective_mark[$i];
// save changes
$assign_subject->save();
}

avoid form data getting clear on form submission

I am using a html form to get user data using laravel php. On form submit I am executing an api which in Web.php is defined as
Route::post('/register_user', 'UserRegistrationController#registerUser');
which executes,
public function registerUser(Request $request){
$apiResult = $this->executeApi($request->input('mobile_no'));
if($apiResult === "Success"){
return view('further_view');
}else{
toastr()->error('Registration Failed. Please check mobile number.');
return back();
}
}
html code
<div class="form-group{{ $errors->has('mobile_no') ? ' has-error' : '' }}">
<label for="mobile_no">Mobile No</label>
<input type="text" name="mobile_no" class="form-control" id="mobile_no" value="{{ old('mobile_no') }}" placeholder="Enter Mobile No" required>
<small class="text-danger">{{ $errors->first('mobile_no') }}</small>
</div>
My issue here is , whenever my $apiResult === "Success" condition goes false, i get toast message on screen but my page get refreshed and all the data user has typed gets cleared from the input box.
Hence my question is how can I show the toast messages without form being cleared or how would I prevent the input box getting cleared on such conditions.
I am using this Toast library
https://github.com/yoeunes/toastr
I would suggest that you use a session to store the data. For example:
session()->put('forms.mobile_no', $request->get('mobile_no'));
Your HTML:
<input value="{{ $mobile_no }}" type="text" name="mobile_no" class="form-control" id="mobile_no" placeholder="Enter Mobile No" required>
Try to return the error message back with this after the toastr call:
return redirect->back()->withInput();

Hide an element when a toggle is checked in PHP/Laravel

I am trying to hide an element on my page when I click a toggle and unhide it when I click the toggle again. Here is my HTML code:
<div class="form-group settings-row">
{{ Form::label('notificationSettings', 'Notification Settings', array('class' => 'col-md-2 control-label')) }}
<div class="col-md-10">
<table style="border-width:0; margin-top:4px;">
<tr>
<td>
Notifications Enabled
</td>
<td>
<div class="onoffswitch" style="margin:4px 0 0 7px;">
<input type="checkbox" #if($notificationsEnabled == true)checked #endif name="notifications_toggle" class="onoffswitch-checkbox" id="notifications_toggle">
<label class="onoffswitch-label" for="notifications_toggle">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</td>
<td></td>
</tr>
</table>
<div class="col-md-10">
#foreach($notificationMessageRadios as $radio)
#if(isset($radio['text']))
<div class="row" style="margin-bottom:1em;">
<input type='radio' name='notificationMessage' id="notificationmessage-other" value="" #if($radio['selected']) checked #endif> {{$radio['message']}}
</div>
<input type="text" id="notificationMessageCustom" placeholder="Pick your own!" #if($radio['selected'])value="{{ $settingsForMessages->notification_message }}" #else value="Pick your own!" #endif name="notificationMessageCustom" class="form-control" #if(!$radio['selected'])style="display:none"#endif>
#else
<div class="row">
<input type='radio' name='notificationMessage' value="{{ $radio['message']}}" #if($radio['selected']) checked #endif> {{ $radio['message'] }}
</div>
#endif
#endforeach
</div>
</div>
</div>
Breakdown:
So when I click the onoffswitch to be on, I want the radios to appear. When I click the onoffswitch to be off, I want the radios to disappear.
I am being thrown into this project, so this code already existed and I am being tasked with editing some features. Any kind of help would be greatly appreciated.
As a bonus, here is the controller side:
$notificationsEnabled = ( $settings['notificationsEnabled'] == 1);
// Cast notification messages to a variable
$notificationMessageMsgs = \Config::get('customer_messages.notificationMessageArray');
$numNotificationMessageMsgs = count($notificationMessageMsgs);
$notificationMessageSelected = false;
// Determine which email subject radio button is checked
foreach($notificationMessageMsgs as $index => $msg) {
$isSelected = false;
if ($settingsForMessages->notification_message == null && $index == 0) {
$notificationMessageSelected = true;
$isSelected = true;
}
if($msg['message'] === $settingsForMessages->notification_message){
$isSelected = true;
$notificationMessageSelected = true;
}
if($index == $numNotificationMessageMsgs - 1 && !$notificationMessageSelected){
$isSelected = true;
}
$notificationMessageRadios[] = array_merge(['selected' => $isSelected], $msg);
}
I am NOT looking for hand holding. I am looking for guidance, that is all.
Maybe try out jQuery?
Try out jQuery Toggle : https://www.w3schools.com/jquery/eff_toggle.asp
$("button").click(function(){
$("p").toggle();
});
This is the code copies from the link . just target your "Class" , "ID" , "element" in the top row $("button") that needs to be clicked and than target the element that needs to be shown/hidden $("p")

Can you assign values to hidden fields in a form, through a php function, to be stored in a database?

I created a form you know; text fields, radio buttons and the submit button
within the said form, I have a div enclosing a section of the radio buttons hidden and a text field upon page load using inline CSS display:none;
If the end user chose yes, the hidden fields will be displayed using a jquery function. If the user chose No or Not Sure, the form will remain hidden or become hidden using the same jquery function.
If the user chose No or Not Sure, i want to automatically assign values for the hidden fields and store them in database.
Here is my form:
<div id = "relation" style = "display: none;">
<p class= "form-p" >Who are you related o?</p>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-4">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" autocomplete="off" name="family" value="Bride" required />Bride
</label>
<label class="btn btn-default">
<input type="radio" autocomplete="off" name="family" value="Groom" required />Groom
</label>
<label class="btn btn-default">
<input type="radio" autocomplete="off" name="family" value="Friend" required />Friend
</label>
<span class="error"><?php echo $famErr;?></span>
</div>
</div>
</div>
<p class = "form-p">Guests in your party, including yourself: </p>
<div class = "form-group">
<label class="control-label col-sm-4"></label>
<div class="col-xs-2">
<input type = "text" class = "form-control" name="num" placeholder = "0" required />
<span class="error"><?php echo $numErr;?></span>
</div>
</div>
</div> <!-- end of id relation-->
Here are the functions:
// function to add RSVP user entry to the database
public function user_attending_storage_RSVP($name, $email, $attend, $fam, $num){
$replies = "INSERT INTO rsvp (name, attending, family, total) VALUES (:name,:attending,:family,:total)";
try{
$query = $this->conn->prepare($replies);
$results = $query->execute(array(":name"=>$name, ":attending"=>$attend, ":family"=>$fam, ":total"=>$num));
}
catch(PDOException $e){
die($e->getMessage());
}
}
// function to add RSVP user entry to the database
public function user_not_attending_storage_RSVP($name, $email, $attend){
$replies = "INSERT INTO rsvp (name, attending, family, total) VALUES (:name,:attending,:family,:total)";
try{
$query = $this->conn->prepare($replies);
$results = $query->execute(array(":name"=>$name, ":attending"=>$attend, ":family"=>$fam, ":total"=>$num));
}
catch(PDOException $e){
die($e->getMessage());
}
}
Here's how I call the function on the webpage
// check for data in fields
if(isset($_POST['name']) ==true && isset($_POST['email']) ==true && isset($_POST['attending']) && isset($_POST['family']) && isset($_POST['num'])){
$name=test_input($_POST['name']);
$email=test_input($_POST['email']);
$attend=test_input($_POST['attending']);
$fam=test_input($_POST['family']);
$num=test_input($_POST['num']);
if($attend == "No" || $attend == "Not Sure"){
$fam = "nothing";
$num = 0;
//inserting user data from form into database
$genQuery->user_Not_attending_storage_RSVP($name, $email, $attend);
}
else{
//inserting user data from form into database
$genQuery->user_attending_storage_RSVP($name, $email, $attend, $fam, $num);
}
// send mail to user
$genQuery->user_invite_confirmation_RSVP($name, $email, $attend,$fam, $num);
}
You can use the getElementById() method...
if(getElementById('input_id').value() == 'no' || getElementById('user_id').value() == 'not sure'){getElementById('input_you_want_to_change).value('Defualt value')}
This will change the value if the user selects no or not sure. Then use PHP to store this new value in the database.

Categories