Basically I have an issue that stems from Joomla 3.1's JSON handling, although because I cannot isolate it I am making this question for direction on it. This will hopefully serve to isolate if this is a bug I should report or something in my application.
Joomla 3.1 seems to have a plugin, or some sort of JSON handling in either the default $model->save() or $table->save(). This can lead to unwanted additions to JSON fields when saving any kind of page. So far looking through the code for them I have been unable to isolate it (witch makes me think plugin, though I only have default enabled.)
So here is the question:
Does Joomla do any JSON handling of form inputs? If so can it be disabled?
To clarify on my personal problem, I have a skeleton component save feature (saves a few minor values to the database, one column is a JSON field). It uses JModelAdmin and through it JTablefor handling the saving of the content. However every item in the JSON array (it is an array of objects) gets duplicated every time it saves. Considering it is a string in a hidden form when it is saved, somewhere in the process it is being parsed into a php array and duplicated by Joomla. Since there is no custom code in the actual saving process it is likely that Joomla has some need to edit JSON values elsewhere and my component triggered it.
here is the form xml if this has anything to do with it, the values hidden form field is what "should" contain the json, it works until you save. That is when every index in the JSON array duplicates.
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field name="id" type="text" class="readonly" label="JGLOBAL_FIELD_ID_LABEL"
description ="JGLOBAL_FIELD_ID_DESC" size="10" default="0"
readonly="true" />
<field name="name" type="text" label="COM_HELLO_COMPANY_FIELD_NAME_LABEL"
description="COM_HELLO_COMPANY_FIELD_NAME_DESC" class="input-xlarge" size="30"
required="true" labelclass="control-label" />
<field name="state" type="list" label="JSTATUS"
description="JFIELD_PUBLISHED_DESC" class="span12 small"
filter="intval" size="1" default="1"
>
<option value="1">
JPUBLISHED</option>
<option value="0">
JUNPUBLISHED</option>
<option value="2">
JARCHIVED</option>
<option value="-2">
JTRASHED</option>
</field>
<field
name="buttonspacer"
description="JGLOBAL_ACTION_PERMISSIONS_DESCRIPTION"
type="spacer" />
<field name="created" type="calendar" label="COM_HELLO_FIELD_CREATED_LABEL"
description="COM_CONTENT_FIELD_CREATED_DESC" class="inputbox" size="22"
format="%Y-%m-%d %H:%M:%S" filter="user_utc" labelclass="control-label" />
<field name="created_by" type="user"
label="COM_HELLO_FIELD_CREATED_BY_LABEL" description="COM_HELLO_FIELD_CREATED_BY_DESC" labelclass="control-label" />
<field name="modified" type="calendar" class="readonly"
label="JGLOBAL_FIELD_MODIFIED_LABEL" description="COM_HELLO_FIELD_MODIFIED_DESC"
size="22" readonly="true" format="%Y-%m-%d %H:%M:%S" filter="user_utc" labelclass="control-label" />
<field name="modified_by" type="user"
label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
class="readonly"
readonly="true"
filter="unset"
labelclass="control-label"
/>
<field name="checked_out" type="hidden" filter="unset" />
<field name="values" type="hidden" />
<field name="checked_out_time" type="hidden" filter="unset" />
<field name="publish_up" type="calendar"
label="COM_HELLO_FIELD_PUBLISH_UP_LABEL" description="COM_HELLO_FIELD_PUBLISH_UP_DESC"
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
filter="user_utc" labelclass="control-label" />
<field name="publish_down" type="calendar"
label="COM_HELLO_FIELD_PUBLISH_DOWN_LABEL" description="COM_HELLO_FIELD_PUBLISH_DOWN_DESC"
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
filter="user_utc" labelclass="control-label" />
<field name="assesments" type="text" label="COM_HELLO_COMPANY_FIELD_ASSESEMENTS_LABEL"
description="COM_HELLO_COMPANY_FIELD_ASSESEMENTS_DESC" class="readonly" size="6"
readonly="true" filter="unset" />
</fieldset>
</form>
Here is my edit.php for the page. It uses JSON to update the values field, the same concept works perfect on the front end of the site and only the administrator side has an issue with it.
<?php
defined('_JEXEC') or die;
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.keepalive');
//JHtml::_('formbehavior.chosen', 'select');
$app = JFactory::getApplication();
$input = $app->input;
if(!empty($this->item->values)){
$values = json_decode($this->item->values);
}else{
$values = array();
}
function setupSelect($selected = 0,$savedValues){
$selectOptions = '';
foreach($savedValues as $value){
$selectOptions .= '<option value="'.$value->id.'"'.($value->id==$selected?' selected="selected"':'').'>'.$value->name.'</option>';
}
return $selectOptions;
}
?>
<script type="text/javascript">
Joomla.submitbutton = function(task){
if(task == 'company.cancel' || document.formvalidator.isValid(document.id('item-form'))){
Joomla.submitform(task, document.getElementById('item-form'));
}
}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_hello&view=company&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="item-form" class="form-validate">
<?php echo JLayoutHelper::render('joomla.edit.item_title', $this); ?>
<div class="row-fluid">
<!-- Begin Content -->
<div class="span10 form-horizontal">
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_HELLO_VALUE_DETAILS', true)); ?>
<fieldset class="adminform">
<div class="control-group form-inline">
<?php echo $this->form->getLabel('name'); ?> <?php echo $this->form->getInput('name'); ?>
</div>
<div>Core Values:</div>
<div class="control-group form-inline">
<div id="core-values" class="accordion">
<?php
if(count($values)):
foreach($values as $value):
$id = uniqid();
?>
<div class="core-value row-fluid">
<div class="accordion-group core-value span9" style="padding:0;">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#core-values" href="#collapse<?php echo $id; ?>">
<select class="value-select">
<option value="0"><?php echo JText::_('COM_HELLO_CORE_VALUES_SELECT_NONE'); ?></option>
<?php echo setupSelect($value->id,$this->values); ?>
</select>
<span class="pull-right" style="height:28px;line-height:28px;">
<span class="icon-plus main"></span>
</span>
</a>
<span class="clearfix"></span>
</div>
<div id="collapse<?php echo $id; ?>" class="accordion-body collapse">
<div class="accordion-inner">
<input type="text" class="outcome-input input-block-level" placeholder="Outcome Statement" value="<?php echo $value->outcome; ?>">
<ul class="behaviors">
<?php
$num = 6;
for($i=0;$i<$num;$i++):
?>
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior" value="<?php echo empty($value->behaviors[$i])?'':$value->behaviors[$i]; ?>"></li>
<?php endfor; ?>
<?php if(count($value->behaviors)>6):
for($i=6;$i<count($value->behaviors);$i++):
?>
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior" value="<?php echo empty($value->behaviors[$i])?'':$value->behaviors[$i]; ?>"></li>
<?php endfor;
endif; ?>
</ul>
<div class="clearfix"></div>
<button type="button" class="btn new-value2 pull-right"><span class="icon-plus no-stop"></span></button>
<div class="clearfix"></div>
</div>
</div>
</div>
<div class="span3" style="line-height:44px;">
<button type="button" class="btn rm-value"><span class="icon-minus"></span></button>
</div>
</div>
<?php
endforeach;
endif;
$id = uniqid();
?>
<div class="core-value row-fluid">
<div class="accordion-group span9" style="padding:0;">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#core-values" href="#collapse<?php echo $id; ?>">
<select class="value-select">
<option value="0"><?php echo JText::_('COM_HELLO_CORE_VALUES_SELECT_NONE'); ?></option>
<?php echo setupSelect(0,$this->values); ?>
</select>
<span class="pull-right" style="height:28px;line-height:28px;">
<span class="icon-plus main"></span>
</span>
</a>
<span class="clearfix"></span>
</div>
<div id="collapse<?php echo $id; ?>" class="accordion-body collapse">
<div class="accordion-inner">
<input type="text" class="outcome-input input-block-level" placeholder="Outcome Statement">
<ul class="behaviors">
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior"></li>
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior"></li>
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior"></li>
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior"></li>
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior"></li>
<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior"></li>
</ul>
<div class="clearfix"></div>
<button type="button" class="btn new-value2 pull-right"><span class="icon-plus no-stop"></span></button>
<div class="clearfix"></div>
</div>
</div>
</div>
<div class="span3" style="line-height:44px;">
<button type="button" class="btn rm-value"><span class="icon-minus"></span></button>
<button type="button" class="btn new-value"><span class="icon-plus"></span></button>
</div>
</div>
</div>
</div>
<?php echo $this->form->getInput('values'); ?>
</fieldset>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'publishing', JText::_('COM_HELLO_FIELDSET_PUBLISHING', true)); ?>
<div class="row-fluid">
<div class="span6">
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('id'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('id'); ?>
</div>
</div>
<div class="control-group">
<?php echo $this->form->getLabel('created_by'); ?>
<div class="controls">
<?php echo $this->form->getInput('created_by'); ?>
</div>
</div>
<div class="control-group">
<?php echo $this->form->getLabel('created'); ?>
<div class="controls">
<?php echo $this->form->getInput('created'); ?>
</div>
</div>
</div>
<div class="span6">
<div class="control-group">
<?php echo $this->form->getLabel('publish_up'); ?>
<div class="controls">
<?php echo $this->form->getInput('publish_up'); ?>
</div>
</div>
<div class="control-group">
<?php echo $this->form->getLabel('publish_down'); ?>
<div class="controls">
<?php echo $this->form->getInput('publish_down'); ?>
</div>
</div>
<?php if ($this->item->modified_by) : ?>
<div class="control-group">
<?php echo $this->form->getLabel('modified_by'); ?>
<div class="controls">
<?php echo $this->form->getInput('modified_by'); ?>
</div>
</div>
<div class="control-group">
<?php echo $this->form->getLabel('modified'); ?>
<div class="controls">
<?php echo $this->form->getInput('modified'); ?>
</div>
</div>
<?php endif; ?>
<?php if ($this->item->assesments) : ?>
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('assesments'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('assesments'); ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="return" value="<?php echo $input->getCmd('return');?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
<!-- End Content -->
<!-- Begin Sidebar -->
<?php echo JLayoutHelper::render('joomla.edit.details', $this); ?>
<!-- End Sidebar -->
</div>
</form>
<script>
var template = jQuery('.core-value:last').clone();
function setupButton(){
jQuery('.new-value').on('click',function(){
var clone = template.clone();
clone.find('.accordion-body').attr('id','collapse'+new Date().getTime());
clone.find('.accordion-toggle').attr('href','#collapse'+new Date().getTime());
jQuery(this).parent().parent().after(clone);
jQuery(this).remove();
setupButton();
setupRm();
});
}
function setupRm(){
jQuery('.rm-value').each(function(){
jQuery(this).off('click').on('click',function(){
var root = jQuery(this).parent().parent();
if(jQuery('.core-value').length==1){
root.replaceWith(template.clone());
setupButton();
setupRm();
}else{
root.remove();
}
});
});
}
function parseBehaviors(root){
var beh = [];
root.find('li').each(function(){
if(jQuery(this).find('.behaviors-input').val()){
beh.push(jQuery(this).find('.behaviors-input').val());
}
});
return beh;
}
jQuery(document).ready(function(){
jQuery('.new-value2').on('click',function(){
var root = jQuery(this).parent();
root.find('.behaviors').append('<li><input type="text" class="behaviors-input input-block-level" placeholder="Behavior"></li>');
});
setupButton();
setupRm();
jQuery('.value-select').on('click',function(event){
event.stopPropagation();
});
jQuery('#core-values').sortable();
jQuery('#core-values').on('shown',function(event){
jQuery(event.target).parent().find('.icon-plus.main').removeClass('icon-plus').addClass('icon-minus');
}).on('hidden',function(event){
jQuery(event.target).parent().find('.icon-minus.main').removeClass('icon-minus').addClass('icon-plus');
});
var setRefresh = setInterval(function(){
var arr = [];
jQuery('.core-value').each(function(){
var obj = {};
if(jQuery(this).find('.value-select option:selected').val()!=0){
obj.id=jQuery(this).find('.value-select option:selected').val();
obj.name=jQuery.trim(jQuery(this).find('.value-select option:selected').text());
obj.outcome=jQuery(this).find('.outcome-input').val();
obj.behaviors=parseBehaviors(jQuery(this).find('.behaviors'));
arr.push(obj);
}
});
var parse = JSON.stringify(arr);
jQuery('#jform_values').val(parse);
},200);
});
</script>
The entire thing functions as a very dynamic and compressed custom form input. So that being said I must have the JSON served as a string and since there is really no point to me doing my own handling of it I don't bother with doing any save overrides in the model/table as the default functions for joomla "should" work. My next step is to override JTable/JModelAdmin almost completely to make sure I get this problem dealt with (although there is still a chance part of my code is where this comes from, though after hunting for hours already I have pretty much given up hope on that).
I have also added this to the Joomla Issue Tracker
Tracker
In there I have included a couple screenshots. Although it links to the same thing, also posted this as an issue on the cms repo.
GitHub
Either way if no answer gets found I will figure this out one way or another, I am thankful for anyone who can assist as this is a critical error in this component, not necessarily Joomla, but if it truly is a bug with 3.1 I can imagine I will be the first of many to run into this.
Related
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.
I'm Working on a Webshop for a School Project. The website is done and works as intended. Except for the Search function, which works but does something weird.
This is the Code from my Search Page
<?php
$stmt = $auth_user->runQuery("SELECT * FROM customer WHERE id=:id");
$stmt->execute(array(":id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if(isset($_POST['btn-offer']))
{
try
{
$auth_user->redirect('offer.php');
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
<form method="post" class="form-signin">
<div class="form-group">
<input type="text" class="form-control" name="search" placeholder="Enter an Item"/> <br />
<button type="Search" name="btn-search">
<i class="glyphicon glyphicon-open-file"></i> Search
</button>
<hr />
</div>
<?php
if(isset($error)){
foreach($error as $error){
?>
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?>
</div>
<?php
}
}
else if(isset($_GET['search'])){
//$search_term = $_SESSION['search_term'];
$stmt = $user_req->runQuery("SELECT * FROM requests WHERE item LIKE :search");
$stmt->bindValue(":search","%".$_SESSION['search_term']."%");
$stmt->execute();
while($userReq=$stmt->fetch(PDO::FETCH_ASSOC)){
?><h6> Request ID </h6><?php echo($userReq['id']); ?> <br /><br /> <?php
?><h6> Requested Item </h6><?php echo($userReq['Item']); ?> <br /><br /> <?php
?><h6> Requested Price </h6><?php echo($userReq['price']); ?> <br /><br /> <?php
?><h6> Requested Quantity </h6><?php echo($userReq['quantity']); ?> <br /><br /> <?php
?><h6> Subject </h6><?php echo($userReq['subject']); ?> <br /><br /> <?php
?><h6> Description </h6><?php echo($userReq['descr']);
?>
<br />
<form action="offer.php" method="post" class="form-signin">
<input type="hidden" class="form-control" name="offer_id" value="<?php echo htmlspecialchars($userReq['id']); ?>"/> <br />
<input type="hidden" class="form-control" name="offer_item" value="<?php echo htmlspecialchars($userReq['Item']); ?>"/> <br />
<button type="Search" name="btn-offer">
<i class="glyphicon glyphicon-open-file"></i> Create Offer
</button>
</form>
<form action="all_offers.php" method="post" class="form-signin">
<input type="hidden" class="form-control" name="offer_id" value="<?php echo htmlspecialchars($userReq['id']); ?>"/> <br />
<button type="Search" name="btn-show">
<i class="glyphicon glyphicon-open-file"></i> Show Offers
</button>
</form>
<hr />
<?php
}
?>
<?php
}
?>
<br />
</form>
It displays everything as desired (all entries containing the search input).
But if i click on Create Offer, the hidden Input Types gets passed to my Search function just once. It wont update it with the new hidden variables if i click on another create offer button.
Offer.php file
<?php
if(isset($_POST['offer_id']))
{
$_SESSION['off_rid'] = $_POST['offer_id'];
$_SESSION['offer_item'] = $_POST['offer_item'];
}
?>
<h2 class="form-signin-heading">Create Offer for Request ID <?php echo htmlspecialchars($_SESSION['off_rid']); ?></h2><hr />
<form method="post" class="form-signin">
<input type="hidden" class="form-control" name="off_rid" value="<?php echo htmlspecialchars($_SESSION['off_rid']); ?>"/> <br />
<div class="form-group">
<label>Requested Item</label>
<input type="text" class="form-control" name="off_item" placeholder="<?php echo htmlspecialchars($_SESSION['offer_item']); ?>" value="<?php if(isset($error)){echo htmlspecialchars($_SESSION['offer_item']);}?>" readonly/>
</div>
<div class="form-group">
<input type="number" class="form-control" name="off_price" placeholder="Enter a Price" value="<?php if(isset($error)){echo $off_price;}?>" />
</div>
<div class="form-group">
<input type="number" class="form-control" name="off_quant" placeholder="Enter the Quantity" value="<?php if(isset($error)){echo $off_quant;}?>" />
</div>
<hr />
<div class="form-group">
<button type="submit" name="btn-createoffer">
<i class="glyphicon glyphicon-open-file"></i> Post Offer
</button>
</div>
<?php
if(isset($error)){
foreach($error as $error){
?>
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?>
</div>
<?php
}
}
else if(isset($_GET['posted'])){
?>
<div class="alert alert-info">
<i class="glyphicon glyphicon-log-in"></i> Successfully submitted the Offer!
</div>
<?php
}
?>
<br />
</form>
If i search for every entry containing "ni" i get all the entries, the hidden Inputtypes are also correct.
If i click on create offer it should write the id and the item on the redirected Page but it only works once. if i go back and search another item it still displays the info from the first item i created an offer.
Can anybody point out what i'm doing wrong. I'm stuck on this Problem since a few days and just cant figure it out.
Thanks in advance
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
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.
I have web script that shows
406 Not Acceptable Error
An appropriate representation of the requested resource /admincp/settings.php could not be found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."
Problem is it works on some hosting providers. Can anyone tell me why is this error coming
<?php
$act=isset($_GET['act'])?$_GET['act']:"";
if($act=='sub'){
$name = $mysqli->escape_string($_POST['site']);
$siteurl = $mysqli->escape_string($_POST['siteurl']);
$keys = $mysqli->escape_string($_POST['keywords']);
$desc = $mysqli->escape_string($_POST['descrp']);
$email = $mysqli->escape_string($_POST['email']);
$active = $mysqli->escape_string($_POST['active']);
$template = $mysqli->escape_string($_POST['template']);
$mysqli->query("UPDATE settings SET name='$name',siteurl='$siteurl',keywords='$keys',descrp='$desc',email='$email',active='$active',template='$template' WHERE id=1");
if($_FILES["file"]["name"]!=''){
move_uploaded_file($_FILES["file"]["tmp_name"], "../images/logo.png");
}?>
<div class="msg-ok">updated successfully.</div>
<?php }
if($settings = $mysqli->query("SELECT * FROM settings WHERE id='1'")){
$setrow = mysqli_fetch_array($settings);
$name=$setrow['siteurl'];
$settings->close();
}else{
printf("Error: %s\n", $mysqli->error);
}
?>
<form action="settings.php?act=sub" method="post" enctype="multipart/form-data">
<label class="artlbl">Site Name</label>
<div class="formdiv">
<input type="text" name='site' value='<?php echo $setrow['name']?>'/>
</div>
<label class="artlbl">Logo (182px x 47px)</label>
<div class="formdiv">
<input type='file' class="file" name='file'/>
</div>
<div class="clear"></div>
<label class="artlbl">Site URL (without "http://" and end "/")</label>
<div class="formdiv">
<input type="text" name='siteurl' value='<?php echo $setrow['siteurl']?>'/>
</div>
<div class="clear"></div>
<label class="artlbl">Meta Keywords (Separated by Commas)</label>
<div class="formdiv">
<textarea name='keywords' cols=40 rows=5 ><?php echo $setrow['keywords']?></textarea>
</div>
<label class="artlbl">Meta Description</label>
<div class="formdiv">
<textarea name='descrp' cols=40 rows=5 ><?php echo $setrow['descrp']?></textarea>
</div>
<label class="artlbl">Email</label>
<div class="formdiv">
<input type="text" name='email' value='<?php echo $setrow['email']?>'/>
</div>
<label class="artlbl">Approve</label>
<div class="formdiv">
<select name="active" id="active">
<?php if ($setrow['active']==1){?>
<option value="1">ON</option>
<option value="0">OFF</option>
<?php }else{?>
<option value="0">OFF</option>
<option value="1">ON</option>
<?php }?>
</select>
</div>
<div class="clear"></div>
<label class="artlbl">Template</label>
<div class="formdiv">
<select name="template" id="template">
<option value="<?php echo $setrow['template'];?>"><?php echo ucfirst($setrow['template']);?></option>
<?php
foreach(glob('../templates/*', GLOB_ONLYDIR) as $dir) {
$TemplateDir = substr($dir, 13);
$TemplateName = ucfirst($TemplateDir)
?>
<option value="<?php echo $TemplateDir;?>"><?php echo $TemplateName;?></option>
<?php }?>
</select>
</div>
<div class="clear"></div>
</br>
<div class="formdiv">
<div class="sbutton"><input type="submit" id="submit" value="Update Site Settings"/></div>
</div>
</form>
<select name="active" id="active"> , can you change name as well as id to something other than active , as active is a keyword.
this problem is caused by apache's mod_security, it scan the request and block it if it contain links.
try to submit this value of $_POST['siteurl'] without the http:// part, that will solve the problem in that case, but you should still contact your hosting provider about that issue.