Ive built a basket/checkout system for an e-commerce site, and have used session variables to store product name, price and quantity and can have them be displayed on my checkout page.
I'm struggling to be able to add different products to the basket, when the user goes to another product and clicks the add to basket button it removes the first product from the basket. does anyone know how I could change my code so that different products can be added to the basket without removing any products that are currently in the variable. and also how could I add the Quantity to the URL so that I can add it to the basket. the quantity is an input box on the products page that the user can tryp the number of products into.
this is my products page -
<?php
require('includes/application_top.php');
$page_title='Details';
require('includes/site_header.php');
$_GET['prod_ID'];
$product_id = isset($_REQUEST['prod_ID']) ? (int) $_REQUEST['prod_ID'] : 0;
$pound ="£";
?>
<style>
<?php
require('css/prod_details.css');
?>
</style>
<br>
<br>
<br>
<br>
<br>
<?php $product = get_product_details1($freshKickz_conn); ?>
<?php foreach($product as $productdetails) {
?>
<main class="container">
<!-- Left Column / Headphones Image -->
<div class="left-column">
<img data-image="red" class="active" src="<?= htmlspecialchars($productdetails['images']) ?>" style="height: 400px; width: 400px;" alt="">
</div>
<!-- Right Column -->
<div class="right-column">
<!-- Product Description -->
<div class="product-description">
<h1><?= htmlspecialchars($productdetails['prod_Name']) ?></h1>
<p><?= htmlspecialchars($productdetails['prod_Details']) ?></p>
</div>
<!-- Product Pricing -->
<div class="product-price">
<span><?=$pound?><?= htmlspecialchars($productdetails['prod_Price'])?></span>
Add to Basket
</div>
<br>
<div class="quantity">
<span>Quantity</span>
<br>
<input type="number" min="1" max="9" step="1" value="1">
</div>
</div>
</main>
<?php
} ?>
<script src="js/prodJS.js"></script>
<script>
$(document).ready(function () {
$('.color-choose input').on('click', function () {
var headphonesColor = $(this).attr('data-image');
$('.active').removeClass('active');
$('.left-column img[data-image = ' + headphonesColor + ']').addClass('active');
$(this).addClass('active');
});
});
</script>
<?php
require('includes/application_bottom.php');
require('includes/site_footer.php');
?>
and this is my basket/checkout page -
<?php
require('includes/application_top.php');
$page_title='Your Basket';
require('includes/site_header.php');
if ( ! isset($_SESSION['basket'])) {
$_SESSION['basket'] = array();
}
$pound ="£";
$action = $_REQUEST['action'] ?? '';
$err = '';
if($_REQUEST['action']=='add_product'){
$_SESSION['basket'][$_REQUEST['name']]=$_REQUEST['quantity']=$_REQUEST['quantity'];
}
?>
<style>
<?php
require('css/basket.css');
?>
</style>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="row">
<div class="col-75">
<div class="container">
<form action="successful_order.php">
<div class="row">
<div class="col-50">
<h3>Billing Address</h3>
<label for="fname"><i class="fa fa-user"></i> Full Name</label>
<input type="text" id="fname" name="firstname" placeholder="John M. Doe">
<label for="email"><i class="fa fa-envelope"></i> Email</label>
<input type="text" id="email" name="email" placeholder="john#example.com">
<label for="adr"><i class="fa fa-address-card-o"></i> Address</label>
<input type="text" id="adr" name="address" placeholder="542 W. 15th Street">
<label for="city"><i class="fa fa-institution"></i> City</label>
<input type="text" id="city" name="city" placeholder="New York">
<div class="row">
<div class="col-50">
<label for="state">County</label>
<input type="text" id="county" name="county" placeholder="Cheshire">
</div>
<div class="col-50">
<label for="zip">PostCode</label>
<input type="text" id="postcode" name="postcode" placeholder="SK11 6TF">
</div>
</div>
</div>
<div class="col-50">
<h3>Payment</h3>
<label for="fname">Accepted Cards</label>
<div class="icon-container">
<i class="fa fa-cc-visa" style="color:navy;"></i>
<i class="fa fa-cc-amex" style="color:blue;"></i>
<i class="fa fa-cc-mastercard" style="color:red;"></i>
<i class="fa fa-cc-discover" style="color:orange;"></i>
</div>
<label for="cname">Name on Card</label>
<input type="text" id="cname" name="cardname" placeholder="John More Doe">
<label for="ccnum">Credit card number</label>
<input type="text" id="ccnum" name="cardnumber" placeholder="1111-2222-3333-4444">
<label for="expmonth">Exp Month</label>
<input type="text" id="expmonth" name="expmonth" placeholder="September">
<div class="row">
<div class="col-50">
<label for="expyear">Exp Year</label>
<input type="text" id="expyear" name="expyear" placeholder="2018">
</div>
<div class="col-50">
<label for="cvv">CVV</label>
<input type="text" id="cvv" name="cvv" placeholder="352">
</div>
</div>
</div>
</div>
<label>
<input type="checkbox" checked="checked" name="sameadr"> Shipping address same as billing
</label>
<input type="submit" value="Checkout" class="btn">
</form>
</div>
</div>
<div class="col-25">
<div class="container">
<h4>Cart
<span class="price" style="color:black">
<i class="fa fa-shopping-cart"></i>
</span>
</h4>
<br>
<br>
<p><span class="name"><?= $_REQUEST['name'] ?></span> <span class="price"><span class="name"><?= $_REQUEST['quantity'] ?><br></span><?= $pound ?><?= $_REQUEST['price'] ?></span></p>
<hr>
<p>Total <span class="price" style="color:black"><b>$30</b></span></p>
</div>
</div>
</div>
<?php
require('includes/application_bottom.php');
require('includes/site_footer.php');
?>
First of all you should avoid using GET request to perform an action.
Next try to use product id because name can be same for different products.
So my offer for product page:
<?php
require('includes/application_top.php');
$page_title='Details';
require('includes/site_header.php');
$product_id = isset($_REQUEST['prod_ID']) ? (int) $_REQUEST['prod_ID'] : 0;
$pound ="£";
?>
<style>
<?php
require('css/prod_details.css');
?>
</style>
<br>
<br>
<br>
<br>
<br>
<?php $product = get_product_details1($freshKickz_conn); ?>
<?php foreach($product as $productdetails): ?>
<main class="container">
<!-- Left Column / Headphones Image -->
<div class="left-column">
<img data-image="red" class="active" src="<?= htmlspecialchars($productdetails['images']) ?>" style="height: 400px; width: 400px;" alt="">
</div>
<!-- Right Column -->
<div class="right-column">
<!-- Product Description -->
<div class="product-description">
<h1><?= htmlspecialchars($productdetails['prod_Name']) ?></h1>
<p><?= htmlspecialchars($productdetails['prod_Details']) ?></p>
</div>
<!-- Product Pricing -->
<form action="basket_page.php" method="POST">
<div class="product-price">
<span><?=$pound?><?= htmlspecialchars($productdetails['prod_Price'])?></span>
<input type="hidden" name="action" value="add_product" />
<!-- i'm not sure what index did you use for id so -->
<input type="hidden" name="id" value="<?php echo htmlspecialchars($productdetails['prod_Name']); ?>" />
<input type="hidden" name="price" value="<?php echo htmlspecialchars($productdetails['prod_Price']); ?>" />
<input type="hidden" name="name" value="<?php echo htmlspecialchars($productdetails['prod_Name']); ?>" />
<button type="submit" class="cart-btn">Add to Basket</button>
</div>
<br>
<div class="quantity">
<span>Quantity</span>
<br>
<input type="number" min="1" max="9" step="1" value="1">
</div>
</form>
</div>
</main>
<?php endforeach; ?>
<script src="js/prodJS.js"></script>
<script>
$(document).ready(function () {
$('.color-choose input').on('click', function () {
var headphonesColor = $(this).attr('data-image');
$('.active').removeClass('active');
$('.left-column img[data-image = ' + headphonesColor + ']').addClass('active');
$(this).addClass('active');
});
});
</script>
<?php
require('includes/application_bottom.php');
require('includes/site_footer.php');
?>
Next you can use associative array for your session. Don't forget to check all user input. It is important.
<?php
require('includes/application_top.php');
$page_title = 'Your Basket';
require('includes/site_header.php');
if (!isset($_SESSION['basket'])) {
$_SESSION['basket'] = [];
}
$pound = "£";
$action = $_REQUEST['action'] ?? '';
$err = '';
if ($action === 'add_product') {
$id = isset($_POST['id']) ? (int) $_POST['id'] : null;
$price = isset($_POST['price']) ? (float) $_POST['price'] : null;
$number = isset($_POST['number']) ? (int) $_POST['number'] : null;
$name = isset($_POST['name']) ? trim($_POST['name']) : null;
if ($id && $price && $number) {
$_SESSION['basket'][$id] = [
'id' => $id,
'price' => $price,
'number' => $number,
'name' => $name,
];
}
}
?>
Next you have an error in rendering. You should use your session array. Not a raw input.
<div class="col-25">
<div class="container">
<h4>
Cart
<span class="price" style="color:black">
<i class="fa fa-shopping-cart"></i>
</span>
</h4>
<br>
<br>
<?php
$total = 0;
foreach ($_SESSION['basket'] as $item):
$total += $item['price'] * $item['number'];
?>
<p>
<span class="name"><?php echo htmlspecialchars($item['name']) ?></span>
<span class="price">
<span class="name"><?= $item['number'] ?><br></span>
<?= $pound ?><?= $item['price'] ?>
</span>
</p>
<hr>
<?php endforeach; ?>
<p>
Total <span class="price" style="color:black"><b>$<?= total ?></b></span>
</p>
</div>
</div>
And finally please take a look at specialized php scripts for ecommerce like WooCommerce or Magento.
Related
i display with a foreach the content of a user_meta in wordpress. It displays input taht fills with the values (so they can be changed). I want to be able to store each content in a new array (so i can update the user_meta next.
So here is the main code :
<?php
function edit_profile_form() {
$current_user_id = get_current_user_id();
$data = get_user_meta ($current_user_id);
if (isset($_POST['button2'])) {
delete_user_meta($current_user_id, 'experiences');
}
if(isset($_POST['button1'])) {
save_extra_profile_fields($current_user_id);
};
$experiences = get_user_meta($current_user_id, 'experiences', true);
?>
<div class="container_form">
<form method="POST">
<h3>Vos expériences</h3>
<div class="experiences_container">
<?php
if (!empty($experiences)) {
$index=0;
foreach ($experiences as $key) {
$index++;
echo($index);
echo($key);
?>
<div class="past_experience">
<div class="experience_header">
<div>
<label for="team">Nom de l'équipe</label>
<input class="team" name="team" value="<?= $key['new_experience_team'];?>"/>
</div>
<div>
<label for="role">Rôle dans l'équipe</label>
<input class="role" name="role" value="<?= $key['new_experience_role'];?>"/>
</div>
</div>
<div class="experience_textarea">
<label for="description">Description du rôle</label>
<textarea class="description" name="description"><?= $key['new_experience_description']; ?></textarea>
<label for="palmares">Palmarés avec l'équipe</label>
<textarea class="palmares" name="palmares"><?= $key['new_experience_palmares']; ?></textarea>
</div>
</div>
<?php
}
} else {
?>
<div><p>Vous n'avez encore rentré aucune expérience</p></div>
<?php
}?>
</div>
<div class="add_container">
<div id="dropdown">
<i class="fas fa-plus-square" style="margin-right: 5px;"></i>
<p id="show" onClick="dropdown()" >Ajouter une expérience</p>
</div>
<div id="experience" style="display:none;">
<label for="new_experience_team">Nom de l'équipe</label>
<input type="text" name="experiences[new_experience_team]" id="experience_team">
<label for="new_experience_role">Rôle dans l'équipe</label>
<input type="text" name="experiences[new_experience_role]" id="experience_role">
<label for="new_experience_description">Description du poste</label>
<textarea type="text" name="experiences[new_experience_description]" id="experience_description"></textarea>
<label for="new_experience_palmares">Palmarés</label>
<textarea type="text" name="experiences[new_experience_palmares]" id="experience_palmares"></textarea>
</div>
</div>
<div id="button_container">
<input type="submit" name="button1" value="Sauvegarder" id='save'/>
<input type="submit" name="button2" value="Annuler"/>
</div>
</form>
</div>
The function's one :
<?php
function save_extra_profile_fields( $user_id ) {
if (!empty($_POST['experiences'])) {
$savedexperience = get_user_meta($user_id, 'experiences', true);
if (!empty($savedexperience) && is_array($savedexperience )) {
$experiences = $savedexperience;
}
$experiences[] = $_POST['experiences'];
update_usermeta($user_id, 'experiences', $experiences);
}
}
So i want to be able to stock in a array each group of team, role, description and palmares.
I don't know if it's clear at all :/
Thanks all
I'm developing a Magento 2.2 site using Hiddentechies_Pixtron theme and I'm trying to override register.phtml without success.
I've follow many tutorials:
https://blog.qaisarsatti.com/magento_2/magento-2-override-default-theme-template-files/
https://magento.stackexchange.com/questions/212218/override-list-phtml-magento-2-2-2
and so on...
In substance I've copied layout and template repectively .xml and .phtml file from
/public_html/vendor/magento/module-customer/view/frontend
and past them inside
/public_html/app/design/frontend/Hiddentechies/pixtron/Magento_Customer
to check if the template is correctly ovveride I put a text inside register.phtml:
<p>this is override;</p>
in fact my file inside /public_html/app/design/frontend/Hiddentechies/pixtron/Magento_Customer/template is
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// #codingStandardsIgnoreFile
/** #var \Magento\Customer\Block\Form\Register $block */
?>
<?= $block->getChildHtml('form_fields_before') ?>
<?php /* Extensions placeholder */ ?>
<?= $block->getChildHtml('customer.form.register.extra') ?>
<p>questo è l'override;</p>
<form class="form create account form-create-account" action="<?= $block->escapeUrl($block->getPostActionUrl()) ?>" method="post" id="form-validate" enctype="multipart/form-data" autocomplete="off">
<?= /* #noEscape */ $block->getBlockHtml('formkey'); ?>
<fieldset class="fieldset create info">
<legend class="legend"><span><?= $block->escapeHtml(__('Personal Information')) ?></span></legend><br>
<input type="hidden" name="success_url" value="<?= $block->escapeUrl($block->getSuccessUrl()) ?>">
<input type="hidden" name="error_url" value="<?= $block->escapeUrl($block->getErrorUrl()) ?>">
<?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
<?php if ($block->isNewsletterEnabled()): ?>
<div class="field choice newsletter">
<input type="checkbox" name="is_subscribed" title="<?= $block->escapeHtmlAttr(__('Sign Up for Newsletter')) ?>" value="1" id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
<label for="is_subscribed" class="label"><span><?= $block->escapeHtml(__('Sign Up for Newsletter')) ?></span></label>
</div>
<?php /* Extensions placeholder */ ?>
<?= $block->getChildHtml('customer.form.register.newsletter') ?>
<?php endif ?>
<?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
<?php if ($_dob->isEnabled()): ?>
<?= $_dob->setDate($block->getFormData()->getDob())->toHtml() ?>
<?php endif ?>
<?php $_taxvat = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?>
<?php if ($_taxvat->isEnabled()): ?>
<?= $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
<?php endif ?>
<?php $_gender = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?>
<?php if ($_gender->isEnabled()): ?>
<?= $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
<?php endif ?>
</fieldset>
<?php if ($block->getShowAddressFields()): ?>
<fieldset class="fieldset address">
<legend class="legend"><span><?= $block->escapeHtml(__('Address Information')) ?></span></legend><br>
<input type="hidden" name="create_address" value="1" />
<?php $_company = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Company') ?>
<?php if ($_company->isEnabled()): ?>
<?= $_company->setCompany($block->getFormData()->getCompany())->toHtml() ?>
<?php endif ?>
<?php $_telephone = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Telephone') ?>
<?php if ($_telephone->isEnabled()): ?>
<?= $_telephone->setTelephone($block->getFormData()->getTelephone())->toHtml() ?>
<?php endif ?>
<?php $_fax = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Fax') ?>
<?php if ($_fax->isEnabled()): ?>
<?= $_fax->setFax($block->getFormData()->getFax())->toHtml() ?>
<?php endif ?>
<?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?>
<div class="field street required">
<label for="street_1" class="label"><span><?= $block->escapeHtml(__('Street Address')) ?></span></label>
<div class="control">
<input type="text" name="street[]" value="<?= $block->escapeHtmlAttr($block->getFormData()->getStreet(0)) ?>" title="<?= $block->escapeHtmlAttr(__('Street Address')) ?>" id="street_1" class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
<div class="nested">
<?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
<?php for ($_i = 2, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i <= $_n; $_i++): ?>
<div class="field additional">
<label class="label" for="street_<?= /* #noEscape */ $_i ?>">
<span><?= $block->escapeHtml(__('Address')) ?></span>
</label>
<div class="control">
<input type="text" name="street[]" value="<?= $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>" title="<?= $block->escapeHtmlAttr(__('Street Address %1', $_i)) ?>" id="street_<?= /* #noEscape */ $_i ?>" class="input-text <?= $block->escapeHtmlAttr($_streetValidationClass) ?>">
</div>
</div>
<?php endfor; ?>
</div>
</div>
</div>
<div class="field required">
<label for="city" class="label"><span><?= $block->escapeHtml(__('City')) ?></span></label>
<div class="control">
<input type="text" name="city" value="<?= $block->escapeHtmlAttr($block->getFormData()->getCity()) ?>" title="<?= $block->escapeHtmlAttr(__('City')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city')) ?>" id="city">
</div>
</div>
<div class="field region required">
<label for="region_id" class="label"><span><?= $block->escapeHtml(__('State/Province')) ?></span></label>
<div class="control">
<select id="region_id" name="region_id" title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>" class="validate-select" style="display:none;">
<option value=""><?= $block->escapeHtml(__('Please select a region, state or province.')) ?></option>
</select>
<input type="text" id="region" name="region" value="<?= $block->escapeHtml($block->getRegion()) ?>" title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>" style="display:none;">
</div>
</div>
<div class="field zip required">
<label for="zip" class="label"><span><?= $block->escapeHtml(__('Zip/Postal Code')) ?></span></label>
<div class="control">
<input type="text" name="postcode" value="<?= $block->escapeHtmlAttr($block->getFormData()->getPostcode()) ?>" title="<?= $block->escapeHtmlAttr(__('Zip/Postal Code')) ?>" id="zip" class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode')) ?>">
</div>
</div>
<div class="field country required">
<label for="country" class="label"><span><?= $block->escapeHtml(__('Country')) ?></span></label>
<div class="control">
<?= $block->getCountryHtmlSelect() ?>
</div>
</div>
<?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes');?>
<?php if ($addressAttributes): ?>
<?php $addressAttributes->setEntityType('customer_address'); ?>
<?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]');?>
<?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address');?>
<?= $addressAttributes->setShowContainer(false)->toHtml() ?>
<?php endif;?>
<input type="hidden" name="default_billing" value="1">
<input type="hidden" name="default_shipping" value="1">
</fieldset>
<?php endif; ?>
<fieldset class="fieldset create account" data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
<legend class="legend"><span><?= $block->escapeHtml(__('Sign-in Information')) ?></span></legend><br>
<div class="field required">
<label for="email_address" class="label"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input type="email" name="email" autocomplete="email" id="email_address" value="<?= $block->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
</div>
</div>
<div class="field password required">
<label for="password" class="label"><span><?= $block->escapeHtml(__('Password')) ?></span></label>
<div class="control">
<input type="password" name="password" id="password"
title="<?= $block->escapeHtmlAttr(__('Password')) ?>"
class="input-text"
data-password-min-length="<?= $block->escapeHtmlAttr($block->getMinimumPasswordLength()) ?>"
data-password-min-character-sets="<?= $block->escapeHtmlAttr($block->getRequiredCharacterClassesNumber()) ?>"
data-validate="{required:true, 'validate-customer-password':true}"
autocomplete="off">
<div id="password-strength-meter-container" data-role="password-strength-meter" aria-live="polite">
<div id="password-strength-meter" class="password-strength-meter">
<?= $block->escapeHtml(__('Password Strength')) ?>:
<span id="password-strength-meter-label" data-role="password-strength-meter-label">
<?= $block->escapeHtml(__('No Password')) ?>
</span>
</div>
</div>
</div>
</div>
<div class="field confirmation required">
<label for="password-confirmation" class="label"><span><?= $block->escapeHtml(__('Confirm Password')) ?></span></label>
<div class="control">
<input type="password" name="password_confirmation" title="<?= $block->escapeHtmlAttr(__('Confirm Password')) ?>" id="password-confirmation" class="input-text" data-validate="{required:true, equalTo:'#password'}" autocomplete="off">
</div>
</div>
<?= $block->getChildHtml('form_additional_info') ?>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<button type="submit" class="action submit primary" title="<?= $block->escapeHtmlAttr(__('Create an Account')) ?>"><span><?= $block->escapeHtml(__('Create an Account')) ?></span></button>
</div>
<div class="secondary">
<a class="action back" href="<?= $block->escapeUrl($block->getBackUrl()) ?>"><span><?= $block->escapeHtml(__('Back')) ?></span></a>
</div>
</div>
</form>
<script>
require([
'jquery',
'mage/mage'
], function($){
var dataForm = $('#form-validate');
var ignore = <?= /* #noEscape */ $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null' ?>;
dataForm.mage('validation', {
<?php if ($_dob->isEnabled()): ?>
errorPlacement: function(error, element) {
if (element.prop('id').search('full') !== -1) {
var dobElement = $(element).parents('.customer-dob'),
errorClass = error.prop('class');
error.insertAfter(element.parent());
dobElement.find('.validate-custom').addClass(errorClass)
.after('<div class="' + errorClass + '"></div>');
}
else {
error.insertAfter(element);
}
},
ignore: ':hidden:not(' + ignore + ')'
<?php else: ?>
ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
<?php endif ?>
}).find('input:text').attr('autocomplete', 'off');
});
</script>
<?php if ($block->getShowAddressFields()): ?>
<script type="text/x-magento-init">
{
"#country": {
"regionUpdater": {
"optionalRegionAllowed": <?= /* #noEscape */ $block->getConfig('general/region/display_all') ? 'true' : 'false' ?>,
"regionListId": "#region_id",
"regionInputId": "#region",
"postcodeId": "#zip",
"form": "#form-validate",
"regionJson": <?= /* #noEscape */ $this->helper(\Magento\Directory\Helper\Data::class)->getRegionJson() ?>,
"defaultRegion": "<?= (int) $block->getFormData()->getRegionId() ?>",
"countriesWithOptionalZip": <?= /* #noEscape */ $this->helper(\Magento\Directory\Helper\Data::class)->getCountriesWithOptionalZip(true) ?>
}
}
}
</script>
<?php endif; ?>
<script type="text/x-magento-init">
{
".field.password": {
"passwordStrengthIndicator": {
"formSelector": "form.form-create-account"
}
}
}
</script>
and file inside /public_html/app/design/frontend/Hiddentechies/pixtron/Magento_Customer/layout is:
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Customer\Block\Form\Register" name="customer_form_register" template="Magento_Customer::form/register.phtml">
<container name="form.additional.info" as="form_additional_info"/>
<container name="customer.form.register.fields.before" as="form_fields_before" label="Form Fields Before" htmlTag="div" htmlClass="customer-form-before"/>
</block>
</referenceContainer>
</body>
</page>
but in frontend the module loaded is still the vendor register.phtml:
How can I override register.phtml in Magento 2.2?
In order to overwrite a PHTML file, you'll need to follow the exact path from the original location, relative to the Vendor/Module directory.
So if you want to overwrite
module-customer/view/frontend/templates/form/register.phtml,
then you'll need to create a register.phtml file in
app/design/frontend/Hiddentechies/pixtron/Magento_Customer/templates/form/
So it seems like you're just missing the form directory, and also "templates" rather than "template"
There is no need to overwrite the XML file (XML files don't actually overwrite anyway, technically they get merged)
Don't forget to flush cache before refreshing the page
How do I get last month salary, if last month salary was negative then I want to subtract last month negative salary from current month payment? like in pic, mar salary is-32000 so when I pay for April I want to subtract -32000 from April payment
<form role="form" enctype="multipart/form-data" action="<?php echo base_url(); ?>admin/payroll/get_payment/<?php
if (!empty($check_salary_payment->salary_payment_id)) {
echo $check_salary_payment->salary_payment_id;
}
?>" method="post" class="form-horizontal form-groups-bordered">
<div class="col-sm-3" data-spy="scroll" data-offset="0">
<div class="row">
<div class="panel panel-primary fees_payment">
<!-- Default panel contents -->
<div class="panel-heading" >
<div class="panel-title">
<strong>Payment For <?php echo date('F,Y', strtotime($payment_date)) ?></strong>
</div>
</div>
<div class="panel-body">
<div class="">
<label class="control-label" >Gross Salary </label>
<input type="text" name="house_rent_allowance" disabled value="<?php
echo $gross = $emp_salary_info->basic_salary + $emp_salary_info->house_rent_allowance + $emp_salary_info->medical_allowance + $emp_salary_info->special_allowance + $emp_salary_info->fuel_allowance + $emp_salary_info->phone_bill_allowance + $emp_salary_info->other_allowance;
?>" class="salary form-control">
</div>
<div class="">
<label class="control-label" >Total Deduction </label>
<input type="text" name="other_allowance" disabled value="<?php
echo $deduction = $emp_salary_info->tax_deduction + $emp_salary_info->provident_fund + $emp_salary_info->other_deduction;
?>" class="salary form-control">
</div>
<div class="">
<?php
$yourDate = date("Y-m", strtotime($payment_date. " -1 months")); // substract 1 month from that date and converting it into timestamp
echo $yourDate;
?>
<?php
if (!empty($payment_history)): foreach ($payment_history as $v_payment_history) :
?>
<?php
if ((date('F-Y', strtotime($v_payment_history->payment_fo_month == $yourDate ))) && ($v_payment_history->payment_amount < 0 ))
{
echo $negative_payment = $v_payment_history->payment_amount;
} ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="">
<label class="control-label" >Net Salary </label>
<input type="text" id="net_salary" name="other_allowance" disabled value="<?php
if (isset($_POST['security_deposit'])) {
echo $net_salary = $emp_salary_info->basic_salary / 2;
}
else {
echo $net_salary = $gross - $deduction;
}
?>" class="salary form-control">
</div>
<?php if (isset($_POST['security_deposit'])) : ?>
<input type="hidden" name="security_deposit" id="security_deposit" value="<?php echo $net_salary = $emp_salary_info->basic_salary / 2; ?>" class="salary form-control">
<?php endif; ?>
<?php if (!empty($emp_salary_info->security_deposit)): ?>
<div class="">
<label class="control-label" >Security Deposited </label>
<input type="text" id="security_deposit1" name="security_deposit1" disabled value="<?php
echo $security = $emp_salary_info->security_deposit;
?>" class="salary form-control">
</div>
<?php endif; ?>
<?php if (!empty($award_info)): foreach ($award_info as $v_award_info) : ?>
<?php if (!empty($v_award_info->award_amount)): ?>
<div class="">
<label class="control-label" > Advance Salary <small>( <?php echo $v_award_info->award_name; ?> )</small> </label>
<input type="text" name="award_amount" id="award_amount" disabled value="<?php echo $v_award_info->award_amount; ?>" class="salary form-control">
<input type="hidden" name="award[]" value="<?php echo $v_award_info->award_amount; ?>" class="salary form-control">
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<div class="">
<label class="control-label" >Incentive</label>
<input type="text" name="incentive" id="incentive" value="<?php
if (!empty($check_salary_payment->incentive)) {
echo $check_salary_payment->incentive;
}
?>" class="salary form-control">
</div>
<div class="">
<label class="control-label" >Fine Deduction </label>
<input type="text" name="fine_deduction" id="fine_deduction" value="<?php
if (!empty($check_salary_payment->fine_deduction)) {
echo $check_salary_payment->fine_deduction;
}
?>" class="salary form-control">
</div>
<div class="">
<label class="control-label" ><strong>Payment Amount </strong></label>
<input type="text" name="payment_amount" id="payment_amount" value="<?php echo $net_salary; ?>" class="salary form-control">
</div>
<!-- Hidden Employee Id -->
<input type="hidden" id="employee_id" name="employee_id" value="<?php echo $emp_salary_info->employee_id; ?>" class="salary form-control">
<input type="hidden" name="payment_for_month" value="<?php
if (!empty($payment_date)) {
echo $payment_date;
}
?>" class="salary form-control">
<div class=""><!-- Payment Type -->
<label class="control-label" >Payment Type <span class="required"> *</span></label>
<select name="payment_type" class="form-control col-sm-5" onchange="get_payment_value(this.value)" >
<option value="" >Select Payment Type...</option>
<option value="Cash Payment" <?php
if (!empty($check_salary_payment->payment_type)) {
echo $check_salary_payment->payment_type == 'Cash Payment' ? 'selected' : '';
}
?>>Cash Payment</option>
<option value="Cheque Payment" <?php
if (!empty($check_salary_payment->payment_type)) {
echo $check_salary_payment->payment_type == 'Cheque Payment' ? 'selected' : '';
}
?>>Cheque Payment</option>
<option value="Bank Account" <?php
if (!empty($check_salary_payment->payment_type)) {
echo $check_salary_payment->payment_type == 'Bank Account' ? 'selected' : '';
}
?>>Bank Account</option>
</select>
</div><!-- Payment Type -->
<div class="">
<label class="control-label" >Comments </label>
<input type="text" name="comments" value="<?php
if (!empty($check_salary_payment->comments)) {
echo $check_salary_payment->comments;
}
?>" class="salary form-control">
</div>
<div class="form-group margin">
<div class="col-sm-5">
<button type="submit" name="sbtn" value="1" class="btn btn-primary btn-block">Save</button>
</div>
</div>
</div>
</div>
</div>
</div><!--************ Fees payment End ***********-->
</form>
I have tried this code, but this code show negative salary every time, I want to get negative salary only the next month. like in the image if negatively is in March then I want to show it only when I give salary for April. but this code show even when I select may June or any month
<div class="">
<?php
$yourDate = date("Y-m", strtotime($payment_date . " -1 months")); // substract 1 month from that date and converting it into timestamp
echo $yourDate;
?>
<?php if (!empty($payment_history)): foreach ($payment_history as $v_payment_history) : ?>
<?php
if ((date('F-Y', strtotime($v_payment_history->payment_fo_month == $yourDate))) && ($v_payment_history->payment_amount < 0 )) {
echo $negative_payment = $v_payment_history->payment_amount;
}
?>
<?php endforeach; ?>
<?php endif; ?>
</div>
I'm a PHP learner. I have a website built on PHP. On the front end of one of our website pages there are four tabs. See the pic below for reference -
I want to add one more tab here. There should be a simple option of adding content in the admin panel for this tab (Which I have accomplished)
My problem is, when I am adding content to the text area in admin panel and hitting submit, the content disappears. I guess the content is not being stored in the database. I checked the SQL file made the possible changes. Although I'm not sure if I did it right. But I'm quite sure that there's a very small lag here which I am not able to figure out.
P.S. Check the screenshot of admin panel for more clarification about my issue.
The text area with heading Table of Contents - Simple is the one which I added. But as I mentioned, even if add content here and hit submit it becomes blank.
Below is the code of the page in screenshot -
"<?php
require_once '../config/config.php';
require_once '../class/dbclass.php';
require_once 'class/content.php';
require_once 'class/category.php';
require_once 'class/common.php';
require './isLogin.php';
$content = new Content();
$category = new Category();enter code here
$catList = $category->fetchCategoryTree();
//echo '<pre>';
//print_r($catList);
//echo '</pre>';
//exit;
//$catParentList = $category->fetchParentCategory(30);
//echo '<pre>';
//print_r($catParentList);
//echo '</pre>';
//echo implode("->",$catParentList);
//echo '<pre>';
//print_r(array_reverse($catParentList));
//echo '</pre>';
//exit;
$cat_id = 0;
$title = '';
$price = '';
$description = '';
$descriptions = '';
$author = $published = $report_code = '';
$content_id = isset($_REQUEST['id']) && $_REQUEST['id'] != "" ? $_REQUEST['id'] : 0;
//$category_list = $category->getAllCategory();
if ($content_id) {
$contentData = $content->getContentById($content_id);
$cat_id = isset($contentData[0]['cat_id']) ? $contentData[0]['cat_id'] : '';
$title = isset($contentData[0]['title']) ? $contentData[0]['title'] : '';
$price = isset($contentData[0]['price']) ? $contentData[0]['price'] : '';
$description = isset($contentData[0]['description']) ? $contentData[0]['description'] : '';
$descriptions = isset($contentData[0]['descriptions']) ? $contentData[0]['descriptions'] : '';
$report_code = isset($contentData[0]['report_code']) ? $contentData[0]['report_code'] : '';
$published = isset($contentData[0]['published']) ? $contentData[0]['published'] : '';
$author = isset($contentData[0]['author']) ? $contentData[0]['author'] : '';
}
if($content_id == 0)
$pageName = "Add Report";
else
$pageName = "Edit Report";
?>
<?php require_once './includes/header.php'; ?>
<?php require_once './includes/sidebar.php'; ?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<b><?php echo $pageName; ?></b>
</h1>
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i> Home</li>
<li class="active"><?php echo $pageName; ?></li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<?php if (isset($_SESSION['error_message']) && $_SESSION['error_message'] != ''): ?>
<div class="alert alert-danger alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="glyphicon glyphicon-remove"></i></button>
<?php echo $_SESSION['error_message']; ?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['success_message']) && $_SESSION['success_message'] != ''): ?>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="glyphicon glyphicon-remove"></i></button>
<?php echo $_SESSION['success_message']; ?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['info_message']) && $_SESSION['info_message'] != ''): ?>
<div class="alert alert-info alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="glyphicon glyphicon-remove"></i></button>
<?php echo $_SESSION['info_message']; ?>
</div>
<?php endif; ?>
</div><!-- /.box-header -->
<!-- form start -->
<form id="content-form" action="models/contentProcess.php" enctype="multipart/form-data" method="post" novalidate>
<div class="box-body">
<input type="hidden" name="type" value="<?php echo ($content_id == 0) ? "addContent" : "editContent"; ?>">
<input type="hidden" name="content_id" id="content_id" value="<?php echo $content_id ?>">
<div class="form-group">
<label>Select Category</label>
<select id="cat_id" name="cat_id" class="form-control">
<?php foreach ($catList as $cl) { ?>
<option value="<?php echo $cl["id"] ?>" <?php echo ($cl["id"] == $cat_id) ? 'selected' : '' ; ?> ><?php echo $cl["name"]; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>Title</label>
<input type="text" name="title" id="title" placeholder="Enter title" class="form-control" value="<?php echo $title ?>">
</div>
<div class="form-group">
<label>Report Code</label>
<input type="text" name="report_code" id="report_code" placeholder="Enter Report Code" class="form-control" value="<?php echo $report_code ?>">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="btn btn-default btn-file" name="image" id="image">
</div>
<div class="form-group">
<label>Published</label>
<input type="text" name="published" id="published" placeholder="Enter published" class="form-control" value="<?php echo $published ?>">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" name="author" id="author" placeholder="Enter author" class="form-control" value="<?php echo $author ?>">
</div>
<div class="form-group">
<label>Price</label>
<input type="text" name="price" id="price" placeholder="Enter price" class="form-control" value="<?php echo $price ?>">
</div>
<div class="form-group">
<label>Description</label>
<textarea id="description" name="description" class="form-control" rows="10" cols="80">
<?php echo $description; ?>
</textarea>
</div>
<div class="form-group">
<label>Table of Contents - Simple</label>
<textarea id="descriptions" name="descriptions" class="form-control" rows="15" cols="100">
<?php echo $descriptions; ?>
</textarea>
</div>
<button class="btn btn-primary" type="submit" id="submitform">Submit</button>
Cancel
</div>
</form>
</div><!-- /.box -->
</div><!--/.col (left) -->
<!-- right column -->
</div> <!-- /.row -->
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<?php require_once './includes/footer.php'; ?>
<script type="text/javascript" src="<?php echo ADMIN_ROOT; ?>plugins/ckeditor/ckeditor.js"></script>
<script language="javascript">
CKEDITOR.replace('descriptions',{
//uiColor:"#532F12",
toolbar: 'MyToolbar',
});
</script>
<script language="javascript">
CKEDITOR.replace('description',{
//uiColor:"#532F12",
toolbar: 'MyToolbar',
});
</script>"
Code snippet of reportDetail.php
<div class="tab-content" style="min-height:775px;">
<div id="menu1" class="tab-pane <?php if (!isset($_SESSION['user_id'])) { ?>active<?php } ?>" style="overflow: auto;<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>max-height: 1520px;<?php } else { ?> height: 795px;<?php } ?>">
<?= $contentData['description'] ?>
</div>
<div id="menu2" class="tab-pane fade <?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>active in<?php } ?>" style="overflow: auto;<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>max-height: 1520px;<?php } else { ?> height: 795px;<?php } ?>">
<?= $contentData['descriptions'] ?>
</div>
<div id="menu3" class="tab-pane fade <?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>active in1<?php } ?>" >
html:-
<form action="" method="post">
<textarea name="textarea" rows="10" cols="50"></textarea>
<input type="submit" name="submit">
</form>
php:-
if(isset($_POST["submit"]))
{
$yourtextarea= $_POST["textarea"];
}
I am trying to create an array of objects which I can then display, the objects being created when a form has been submitted.
The first object gets successfully added, but when I add another object, it simply overwrites the last created object. Can anyone see where I am going wrong?
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/includes/classes/Goal.php'; ?>
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/global/head.php'; ?>
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/config/init.php'; ?>
<?php
$input['title'] = "";
$input['deadline'] = "";
$input['description'] = "";
if(!isset($_SESSION['goals'])) {$_SESSION['goals'] = array();}
if (isset($_POST['submit'])) {
$_SESSION['goalCount'] ++;
$input['title'] = htmlentities($_POST ['title'],ENT_QUOTES);
$input['deadline'] = htmlentities($_POST ['deadline'],ENT_QUOTES);
$input['description'] = htmlentities($_POST ['description'],ENT_QUOTES);
convertDate($input['deadline']);
${'goal'. $_SESSION['goalCount']} = new Goal($input['title'], $input['description'], $_SESSION['username'], $input['deadline']);
array_push($_SESSION['goals'], ${'goal'. $_SESSION['goalCount']});
?>
<div class="top">
<p>h</p>
</div>
<div class="container">
<div class="sixteen columns topbar">
<?php require $_SERVER['DOCUMENT_ROOT'].'/global/header.php'; ?><!-- Content Begins -->
<div class="content">
<h1> OO Test Page - Batch add goals</h1><hr/>
<div class="six columns">
<form action="" method="post">
<fieldset>
<div>
<h4>Title</h4>
<span id='title-result'></span>
<label for="title"></label><br />
<input type="text" id="title" name="title" placeholder="e.g. Graduate" value="" required aria-required="true">
</div>
<div>
<h4>Description</h4>
<span id='description-result'></span>
<label for="description"></label>
<textarea type="description" id="description" placeholder="e.g. with first-class honours" name="description" value="" required aria-required="true"></textarea>
</div>
<div>
<h4>Deadline</h4>
<span id='description-result'></span>
<label for="deadline"></label>
<input rows="2"type="date" id="datepick" placeholder="" name="deadline" value="" required aria-required="true"/>
</div>
<div class="submit">
<input type="submit" name="submit" value="Add">
</div>
</fieldset>
</form></div>
<div class="ten columns">
<?php
foreach ($_SESSION['goals'] as $goal)
{
echo '<div class="goal"><h4>'. $goal->title .'</h4>'. $goal->desc .'</h4><p>'. $goalCount .'</p></div>';
}
echo Goal::$counter;
var_dump($_SESSION['goals'])
?>
</div>
</div>
<!-- Content Ends -->
<?php require $_SERVER['DOCUMENT_ROOT'].'/global/footer.php'; ?>
</div>
</div>
</body>
</html>
Simply initialize that session variables that you need. And no need to use variable variables and using it as a counter to push inside. Just normally push those object inside the session.
Example:
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/includes/classes/Goal.php'; ?>
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/global/head.php'; ?>
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/config/init.php'; ?>
<?php
if(!isset($_SESSION['goals'], $_SESSION['goalCount'])) {
$_SESSION['goals'] = array();
$_SESSION['goalCount'] = 0;
}
if (isset($_POST['submit'])) {
$_SESSION['goalCount'] += 1;
$input['title'] = htmlentities($_POST ['title'],ENT_QUOTES);
$input['deadline'] = htmlentities($_POST ['deadline'],ENT_QUOTES);
$input['description'] = htmlentities($_POST['description'],ENT_QUOTES);
convertDate($input['deadline']);
$goal = new Goal($input['title'], $input['description'], $_SESSION['username'], $input['deadline']);
$_SESSION['goals'][] = $goal;
// ^ add another dimension
} // missing closing curly brace
?>
<div class="top">
<p>h</p>
</div>
<div class="container">
<div class="sixteen columns topbar">
<?php require $_SERVER['DOCUMENT_ROOT'].'/global/header.php'; ?><!-- Content Begins -->
<div class="content">
<h1> OO Test Page - Batch add goals</h1><hr/>
<div class="six columns">
<form action="" method="POST">
<fieldset>
<div>
<h4>Title</h4>
<span id='title-result'></span>
<label for="title"></label><br />
<input type="text" id="title" name="title" placeholder="e.g. Graduate" value="" required aria-required="true">
</div>
<div>
<h4>Description</h4>
<span id='description-result'></span>
<label for="description"></label>
<textarea type="description" id="description" placeholder="e.g. with first-class honours" name="description" value="" required aria-required="true"></textarea>
</div>
<div>
<h4>Deadline</h4>
<span id='description-result'></span>
<label for="deadline"></label>
<input rows="2"type="date" id="datepick" placeholder="" name="deadline" value="" required aria-required="true"/>
</div>
<div class="submit">
<input type="submit" name="submit" value="Add">
</div>
</fieldset>
</form>
</div>
</div>
<div class="ten columns">
<?php
foreach ($_SESSION['goals'] as $goal) {
echo '<div class="goal"><h4>'. $goal->title .'</h4>'. $goal->desc .'</h4><p>'. $goalCount .'</p></div>';
}
?>
</div>
<!-- Content Ends -->
<?php require $_SERVER['DOCUMENT_ROOT'].'/global/footer.php'; ?>
</div>
</div>
Sidenote: Always turn on error reporting.