Php include header not showing on some machines - php

So i have an header and footer in seperate files, i include them via the php include method. On my machine it works on chrome and edge. When i go to a other pc it works on chrome but not on edge. Now when it doesn't load it actually loads but dissapears directly after. It is only on screen for a short flash.
My file structure is as following:
2.10.0
index.php
assets
headernav.php
In my index.php file i use this code to include.
<?php include("assets/headernav.php"); ?>
The headernav.php file it includes is as follows
<script>
function openmen() {
document.getElementById("menu").style.marginLeft = "0";
document.getElementById('menubtn').setAttribute("onClick", "closemen()");
document.getElementById("content").style.paddingLeft = "250px";
document.getElementById("searchbox").style.left = "240px";
}
function closemen() {
document.getElementById("menu").style.marginLeft = "-230px";
document.getElementById('menubtn').setAttribute("onClick", "openmen()");
document.getElementById("content").style.paddingLeft = "20px";
document.getElementById("searchbox").style.left = "10px";
}
function opensettings() {
document.getElementById("settings").style.display = "block";
}
function closesettings() {
document.getElementById("settings").style.display = "none";
}
</script>
<settings_background id="settings">
<settings>
<h2>Instellingen</h2><i id="closebtn" onclick="closesettings()" class="fas fa-times"></i>
<a>Eenheid</a>
<form method="POST" action="includes/units.inc.php">
<input placeholder="Naam" class="inputmaterial" type="text" name="naam" value="<?php echo $_SESSION['naam']; ?>">
<input placeholder="Callsign" class="inputmaterial" type="text" name="callsign" value="<?php echo $_SESSION['callsign']; ?>">
<select Placeholder="department" class="inputmaterial" name="department">
<option value="<?php echo $_SESSION['department']; ?>"><?php echo $_SESSION['department']; ?></option>
<option value="Police">Police</option>
<option value="Traffic police">Traffic police</option>
<option value="Fire">Fire</option>
<option value="Ems">Ems</option>
<option value="Milatary police">Milatary police</option>
<option value="Siu">Siu</option>
</select>
<input placeholder="rang/functie" class="inputmaterial" type="text" name="rang" value="<?php echo $_SESSION['rang']; ?>">
<input placeholder="Naam" type="hidden" name="id" value="<?php echo $_SESSION["id"]; ?>">
<input type="hidden" name="return" value="index.php">
<br><br><br><input style="float:left;"class="button_grey" type="submit" name="cookie" value="Save">
</form>
<a>Account</a>
<form method="POST" action="login_v3/account.inc.php">
<input placeholder="Huidig wachtwoord" class="inputmaterial" type="password" name="pwdold">
<input placeholder="Nieuw wachtwoord" class="inputmaterial" type="password" name="password">
<input placeholder="uid" type="hidden" name="uid" value="<?php echo $_SESSION['id']; ?>">
<br><br><br><input class="button_grey" type="submit" name="updatepassword" value="Save">
</form>
<a>Personalisatie</a>
<form action="includes/units.inc.php" method="POST">
<input type="checkbox" id="id-name--1" name="meldingen" class="switch-input" <?php if(isset($_SESSION['notificaties'])){echo "checked";} ?>>
<label for="id-name--1" class="switch-label">Meldingen <span class="toggle--on">Aan</span><span class="toggle--off">Uit</span></label>
<input type="checkbox" id="id-name--2" name="darkmode" class="switch-input" <?php if(isset($_SESSION['darkmode'])){echo "checked";} ?>>
<label for="id-name--2" class="switch-label">Darkmode <span class="toggle--on">Aan</span><span class="toggle--off">Uit</span></label><br><br><br>*darkmode is nog in beta
<input placeholder="Naam" type="hidden" name="id" value="<?php echo $_SESSION["id"]; ?>">
<br><br><input type="submit" name="personalisatie" value="Save" class="button_grey">
</form>
</settings>
</settings_background>
<nav_menu id="menu"><div class="section">
<i class="fas fa-phone"></i> Meldingen
<i class="fas fa-id-card"></i> Database
<i class="fas fa-eye"></i> Gezocht
<i class="fas fa-map-marked-alt"></i> Kaarten
</div>
<div class="section">
<p>Verslagen</p>
</i> Verslagen
<a><i class="fas fa-notes-medical"></i> Nieuw verslag</a>
</div>
<div class="section">
<p>Registratie</p>
<i class="fas fa-bell"></i> Maak melding
<i class="fas fa-receipt"></i> Bekeuring
<i class="fas fa-exclamation"></i> Waarschuwing
<i class="fas fa-mask"></i> Misdrijf
<a><i class="fas fa-eye"></i> Arrestatiebevel</a>
</div>
<div class="section">
<p>Database toevoeging</p>
<a><i class="fas fa-car"></i> Voertuig</a>
</div>
<div class="section">
<p>Meldkamer</p>
<i class="fas fa-headset"></i> Meldkamer
</div>
<p>
© www.lscdb.nl
</p>
</nav_menu>
<nav_bar><div class="nav_bar_left"><i id="menubtn" onclick="closemen()" class="fas fa-bars"></i><img src="../img/lscdb_logo_white.png"></div><div class="logged_in"><?php echo $_SESSION['naam']; ?> | <?php echo $_SESSION['callsign']; ?></div><i class="fas fa-question"></i><i class="fas fa-sign-out-alt"></i><i onclick="opensettings()" class="fas fa-cog"></i></nav_bar>
So to conclude, my headernav file i include using php works on some machines, while on others loads and dissapears directly after.

So i found a solution.... finally.
It turns out the header that has a position:fixed allways needs top:0; and left:0;, even if the header is allready in the correct position.

Related

Values received from database aren't displaying properly in php

Hi guys please help me out, I have this php code where I get data from the database and displays on the web and if you check the input hidden tag below I gave it a value but instead not all the values are displaying properly in it. Instead it's creating an attribute.
PHP CODE
<?php
$output = '';
$sqlNO = "SELECT * FROM pnewoffer";
$NOresult = mysqli_query($conn, $sqlNO);
if(mysqli_num_rows($NOresult) > 0) {
while($row = mysqli_fetch_array($NOresult)) {
$output .= '<div class="offer-card">
<form action="./bked/savedit.php" method="post">
<a href="#" class="offer-card-inner">
<div class="offer-img">
<img src="./image/'.$row['offerPImage'].'" alt="New Offer Image" width="200">
</div>
<div class="offer-info">
<h3 class="offer-title">'.$row['offerPName'].'</h3>
<div class="clearfix rating marT8 ">
<div class="rating-stars ">
<div class="grey-stars"></div>
<div class="filled-stars" style="width:60.0%"></div>
</div>
</div>
<h4 class="offer-product-price">N'.$row['offerPPrice'].' </h4>
</div>
</a>
<input type="hidden" name="newPPrice" value='.$row['offerPPrice'].'>
<input type="hidden" name="newPName" value='.$row['offerPName'].'>
<input type="hidden" name="newPImg" value='.$row['offerPImage'].'>
<div class="offer-bt-btn">
<div class="offer-btn">
<button type="submit" name="saveForLater" class="favorite-offer-btn">
<i class="far fa-heart"></i>
</button>
<a href="#" class="offer-product-info-btn">
<i class="fa fa-info"></i>
</a>
</div>
</div>
</form>
</div>';
}
}
echo $output;
?>
RESULT
<input type="hidden" name="newPName" value="Blue" louis="" vuitton="" women="" bag="">
<input type="hidden" name="newPName" value="Samsung" galaxy="" s9="" 6gb="" ram,="" 32gb="" rom,="" 16mpbs="">
its actually supposed to be
<input type="hidden" name="newPName" value="Samsung Galaxy S9 6gb ram, 32gb rom, 16mpbs">
<input type="hidden" name="newPName" value="Blue Louis Vuitton Women Bag">
Please, how do I go about it?
If any of the value contain ' characters, that will end the value attribute and start a new attribute. Use htmlspecialchars() to encode it and prevent this.
<input type="hidden" name="newPPrice" value='.htmlspecialchars($row['offerPPrice'], ENT_QUOTES).'>
<input type="hidden" name="newPName" value='.htmlspecialchars($row['offerPName'], ENT_QUOTES).'>
<input type="hidden" name="newPImg" value='.htmlspecialchars($row['offerPImage'], ENT_QUOTES).'>

Search function with php PDO and mysql

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

How to auto create divs depending on the data in mysql table using php?

I want to create an ecommerce website, using PHP and mySQL DB. I have this code below and I want (with the use of php if possible), after connecting to sql DB(I did this) to repeat this DIV depending on the entries in the DB table and echo the data of each entry in table. I found this but I don't know if it's the right example: Automatically creating div's using data from a sql table
Here's the code:
<div class="col-md-4 agileinfo_new_products_grid agileinfo_new_products_grid_mobiles">
<div class="agile_ecommerce_tab_left mobiles_grid">
<div class="hs-wrapper hs-wrapper2">
<img src="images/<image>.jpg" alt=" " class="img-responsive" />
<div class="hs_bottom hs_bottom_sub1">
<ul>
<li>
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
</li>
</ul>
</div>
</div>
<h5><Itemname></h5>
<div class="simpleCart_shelfItem">
<p><i class="item_price"><Price></i></p>
<p><i class="item_price"><Description></i></p>
<form action="#" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="item" value="Itemname" />
<input type="hidden" name="amount" value="Price"/>
<button type="submit" class="cart">Add to cart</button>
</form>
</div>
</div>
The example you provided above will work just fine, all you need to do is put the div/div's you want to generate multiple times inside a loop. then they will be generated as long as the loop condition is met.
But though the example u provided works but you need to note that it
is using mysql_* functions which are depreciated and no longer
supported by newer php versions .
Therefore I would advice that you learn about prepared statements instead, and use PDO.
consider the following :
<?php
$sql = $pdo->query("SELECT * FROM products")->fetchall(PDO::FETCH_ASSOC);
foreach($sql as $row):?>
<div class="col-md-4 agileinfo_new_products_grid agileinfo_new_products_grid_mobiles">
<div class="agile_ecommerce_tab_left mobiles_grid">
<div class="hs-wrapper hs-wrapper2">
<img src="images/<?php echo $row['productImg'];?>" alt=" " class="img-responsive" />
<div class="hs_bottom hs_bottom_sub1">
<ul>
<li>
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
</li>
</ul>
</div>
</div>
<h5><?php echo $row['item_name'];?></h5>
<div class="simpleCart_shelfItem">
<p><i class="item_price"> Price : <?php echo $row['item_price'];?></i></p>
<p><i class="item_price">Description <?php echo $row['item_description'];?></i></p>
<form action="#" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="item" value="<?php echo $row['item_name'];?>" />
<input type="hidden" name="amount" value="<?php echo $row['item_price'];?>"/>
<button type="submit" class="cart">Add to cart</button>
</form>
</div>
</div>
<?php
endforeach;
?>
OR
<?php
$sql = $pdo->query("SELECT * FROM products");
while ($row = $sql->fetchall(PDO::FETCH_ASSOC)):?>
<div class="col-md-4 agileinfo_new_products_grid agileinfo_new_products_grid_mobiles">
<div class="agile_ecommerce_tab_left mobiles_grid">
<div class="hs-wrapper hs-wrapper2">
<img src="images/<?php echo $row['productImg'];?>" alt=" " class="img-responsive" />
<div class="hs_bottom hs_bottom_sub1">
<ul>
<li>
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
</li>
</ul>
</div>
</div>
<h5><?php echo $row['item_name'];?></h5>
<div class="simpleCart_shelfItem">
<p><i class="item_price"> Price : <?php echo $row['item_price'];?></i></p>
<p><i class="item_price">Description <?php echo $row['item_description'];?></i></p>
<form action="#" method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="item" value="<?php echo $row['item_name'];?>" />
<input type="hidden" name="amount" value="<?php echo $row['item_price'];?>"/>
<button type="submit" class="cart">Add to cart</button>
</form>
</div>
</div>
<?php
endwhile;
?>
Where $pdo is your database connection string.
This will fetch data and generates the div for each product.
If you not using prepared statements for your application, I would advice you to use them more especially pdo prepared statements, below are the places you can learn pdo prepared statements
https://phpdelusions.net/pdo#foreach
http://jayblanchard.net/demystifying_php_pdo.html

nested forloop error in php codeigniter

<?php foreach ($faq as $faq): ?>
<div class="form-group firstedit">
<label class="col-sm-2 control-label">Question : </label>
<div class="col-sm-8">
<input type="text" id="question" class="form-control remove_att" value="<?php echo $faq['faq_question'] ?>" placeholder="Enter the question" readonly="readonly" required="">
</div>
<div class="col-sm-8">
<select data-plugin-selectTwo class="form-control populate" id="category" required="required">
<?php foreach ($category as $category){ ?>
<option value="<?php echo $category['faq_category_id'] ?>"><?php echo $category['faq_category_name'] ?></option>
<?php } ?>
</select>
</div>
<div class="col-sm-2" class="edit_all">
<button type="button" class="btn btn-warning btn-sm show_edit" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit"></i></button>
<button type="button" id="<?php echo $faq['faq_id'] ?>" class="btn btn-success btn-sm save_faq" data-toggle="tooltip" data-placement="bottom" title="Save" style="display: none"><i class="fa fa-floppy-o" ></i></button>
<button type="button" class="btn btn-danger btn-sm delete_faq" id="<?php echo $faq['faq_id'] ?>" data-toggle="tooltip" data-placement="bottom" title="Delete"><i class="fa fa-trash"></i> Delete</button>
</div>
</div>
<div class="form-group answer">
<label class="col-sm-2 control-label">Answer : </label>
<div class="col-sm-8 edit_answer" >
<textarea class="form-control remove_text" id="answer11" rows="5" placeholder="Type your answer..." required="required" readonly ><?php echo $faq['faq_answer'] ?></textarea>
</div>
<div class="col-sm-2">
<?php if ($faq['faq_status'] == "pending") : ?>
<button type="button" class="btn btn-danger btn-sm approve_faq" id="<?php echo $faq['faq_id'] ?>" data-toggle="tooltip" data-placement="bottom" title="Approve FAQ's"><i class="fa fa-trash"></i> approve</button>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
my controller
public function not_approved() {
$category_id = $this->input->post('category_id');
$data['faq'] = $this->faq_model->not_approved($category_id);
// get the faq category
$data['category'] = $this->faq_model->get_category();
// echo "<script>alert('adadsdsa')</script>";
$this->load->view('faq/display_faq_not_approved', $data);
}
I have for-loop for FAQ where display all the FAQ values and I have FAQ category, but in separate table.
I want to display the FAQ category. above I use the nested for-loop but end with an error.
I want to display the nested for loop with in the for-loop for displaying all the category. how to achieve this
Are you using
<?php foreach ($faq as $faq): ?>
Try using some other key, like
<?php foreach ($faq as $f): ?>
Wrong use, keys and values ​​can not be the same.
<?php foreach ($faq as $faq): ?>
<?php foreach ($category as $category){ ?>
for example,
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
http://php.net/manual/en/control-structures.foreach.php
Try
foreach ($faq as $intKey=>$strValue)
so $strValue is the elements as you want

Joomla 3.1 JSON handling

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.

Categories