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
Related
i have a foreach row that displays the "message icon" (i dont think it has anything to do with the form since the form is outside the loop:
enter image description here
which displays a chat form that you can either type a chat or send an attachment:
enter image description here
How can i make one of them required before submission? I tried through multiple JQuery ways but because they are in a for loop and each of them do not have a special id, its not working. any help please? I just need it to show an alert
Here is my code for the form:
<form method="post"action="<?php echo base_url();?>form_support_chat" enctype="multipart/form-data" class="ticket-reply-form">
<div class="row">
<div class="col-xs-12">
<div class="chat-left">
<input type="text" name="message" placeholder="Type Message ..." class="form-control" autocomplete="off">
<input type="hidden" name="cst_id" value="<?php echo $cst_id; ?>">
<input type="hidden" name="arch_ticket" value="<?php echo $arch_ticket; ?>">
<input type="hidden" name="ticket_number" value="<?php echo $ticket_number?>">
</div>
<div class="chat-right">
<label>
<img src="<?php echo base_url();?>/assest/icon-img/paperclip.png" class="ic_img" >
<input type="file" name="file" class="form-control" style="display:none;" id="hidden_upload_file_chatting">
</label>
<button type="submit" class="btn btn-flat" name="reply" value="reply" >Reply</button>
<button type="button" class="btn btn-flat" data-dismiss="modal" style="margin-left: 10px !important;">Close</button>
<span id="_showName"></span>
</div>
</div>
</div>
</form>
Simply use html5's required value
<input name="cst_id" value="<?php echo $cst_id; ?>" required>
or
<input name="cst_id" value="<?php echo $cst_id; ?>" required="true">
update
Using jQuery, add id value to each input
$(document).ready(function() {
if( $('#input1').valid() || $('#input2').valid(); ):
console.log("Success");
endif;
});
I have a form where I enter a username and it gets the users information. after calling for the users information I have another form wtih a checkbox for "banned" where I can ban or unban the user. But how can I store the entered username from the first form, to later use it in the second form where I check the banned checkbox?
code:
<form action="" method="post" id="msform">
<input type="text" name="datausername" placeholder="Username" maxlength="64" readonly onfocus="this.removeAttribute('readonly');"/>
<input type="submit" name="userdata" value="Get Data" class="databutton">
</form>
<?php
if(isset($_POST['userdata'])){
$datausername = $_POST['datausername'];
$sql = "SELECT * FROM users WHERE username = '$datausername'";
$result = $db->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '
<div class="container" style="width:100%;">
<div class="flag note note--secondary">
<div class="flag__body note__text" style="width:100%;">
<h1>Personal Information</h1>
ID : <div class="fr">'.$row['id'].'</div><br />
E-mail: <div class="fr">'.$row['email'].'</div><br />
Username: <div class="fr">'.$row['username'].'</div><br />
Firstname: <div class="fr">'.$row['firstname'].'</div><br />
Lastname: <div class="fr">'.$row['lastname'].'</div><br />
<br />
Activated: <div class="fr">'.$row['active'].'</div><br />
Banned: <div class="fr">'.$row['banned'].'</div><br />
<br />
<h1>Data Information</h1>
Title: <div class="fr">'.$row['title'].'</div><br />
Rank: <div class="fr">'.$row['rank'].'</div><br />
Level: <div class="fr">'.$row['level'].'</div><br />
Exp: <div class="fr">'.$row['exp'].'</div><br />
<br />
<h1>Forum / Profile stats</h1>
Forum Posts: <div class="fr">0</div><br />
Forum Threaths: <div class="fr">0</div><br />
Comments: <div class="fr">0</div><br />
Awards: <div class="fr">0</div><br />
Friends: <div class="fr">0</div><br />
Followers: <div class="fr">0</div><br />
<br />
<h1>Security Information</h1>
IP: <div class="fr">'.$row['ip'].'</div><br />
Last IP: <div class="fr">'.$row['active_ip'].'</div><br />
Secret Question: <div class="fr">'.$row['question'].'</div><br />
Timestamp: <div class="fr">'.$row['timestamp'].'</div><br />
Activate Link: <div class="fr">link</div><br />
<br />
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>';
if($title == 'Head Admin' || $title == 'Admin'){
if($row['banned'] == '1'){
$checkbox = '<label><input type="checkbox" name="confirm" checked/></label>';
} else {
$checkbox = '<label><input type="checkbox" name="confirm" /></label>';
}
echo '
<div class="container" style="margin-top:20px; width:100%;">
<div class="flag note note--secondary">
<div class="flag__body note__text" style="width:100%;">
<h1>Settings</h1>
<form method="post" action="" id="msform" style="text-align:left;">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
</form>
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>
';
}
}
} else {
echo '
<div class="container" style="margin:0 auto; width:100%;">
<div class="flag note note--secondary">
<div class="flag__image note__icon">
<i class="fa fa-user"></i>
</div>
<div class="flag__body note__text">
User not found!
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>';
}
}
$db->close();
?>
This is the second form where I want to have the username stored to re use i to update the "banned" checkmark:
if($title == 'Head Admin' || $title == 'Admin'){
if($row['banned'] == '1'){
$checkbox = '<label><input type="checkbox" name="confirm" checked/></label>';
} else {
$checkbox = '<label><input type="checkbox" name="confirm" /></label>';
}
echo '
<div class="container" style="margin-top:20px; width:100%;">
<div class="flag note note--secondary">
<div class="flag__body note__text" style="width:100%;">
<h1>Settings</h1>
<form method="post" action="" id="msform" style="text-align:left;">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
</form>
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>
PS: title in
if($title == 'Head Admin' || $title == 'Admin'){
Is your logged in title, so this will only be an option if you are either Head Admin or Admin
You can create a hidden text field to store it, then pass it via the POST data to the next stage:
(instead of using datausername here, you should be using the row ID returned from your SQL query)
<form method="post" action="" id="msform" style="text-align:left;">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
<input type="hidden" name="username" value="<?=$datausername?>">
</form>
Then in the next stage $_POST['datausername'] will exist.
OR
Use sessions (the better solution to be honest, less prone to hacking)
For example, you can start a new session, shove some data into it and unset the session after your finished with it.
In your index.php / config.php / whatever
session_start();
In your php file:
$datausername = $_POST['datausername'];
$_SESSION['customdata']['username'] = $datausername;
if($title == 'Head Admin' || $title == 'Admin') {
if ( isset($_SESSION['customdata']) ) {
$username = $_SESSION['customdata']['userid'];
//ban the user here, update SQL etc.
//Unset the session variable
unset($_SESSION['customdata'];
}
}
In your form add a hidden field to contain the id of the user. You can then use that as a key for the update query in the second form
<form method="post" action="" id="msform" style="text-align:left;">
<input type="hidden" name="key" value="<?php echo $row['id']; ?>">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
</form>
Alternativley use the session
In form one add thsi at the top of the script
<?php
session_start();
then load a value ito the session
$_SESSION['Users_id'] = $row['id'];
Now in the second form you will use that value in the UPDATE
<?php
session_start();
if ( isset($_SESSION['users_id']) ) {
$key = $_SESSION['users_id'];
} else {
// we really should not be in this form
header('Location: somewhere_else.php');
}
So I am trying to learn php, I have a simple 1 item order form, However I have 4 items in the data base I need to show on this order form. In javascript I would just write a loop for an array, however the whole php query form a table from a database has got me flustered and I am not sure how to loop the results to show more then the 1 item from the query and the still allow for ordering all on 1 page. Originaly I had it list a table so you would click on the item and it would redirect to a page for each item so each on can be ordered.
<?php
include_once 'helpers/helper.php';
include_once 'db_function.php';
session_start();
$show_query = "SELECT * FROM `meal_info` ORDER BY meal_time DESC LIMIT 4;";
$show_result = db_query($connect, $show_query);
if($show_result) {
$show_result_row = db_fetch_array($show_result);
}
?>
<?php include_once 'layout/header.php'; ?>
<?php
if(#$_SESSION['order_submit_msg']) {
echo flash_message('order_submit_msg');
unset($_SESSION['order_submit_msg']);
}
?>
<div>
<form action="make_deal.php" method="post">
<div>
<h1><?php echo $show_result_row['meal_name'];?></h1>
</div>
<hr>
<div>
<img class="meal-img" id="meal-img" src="<?php echo $show_result_row['meal_image'];?>" alt="">
</div>
<br>
<div>
<h2>Feature: <?php echo $show_result_row['meal_content'];?></h2>
<h3>Price: <?php echo $show_result_row['meal_price'];?></h3>
</div>
<input type="hidden" name="meal-id" value="<?php echo $show_result_row['meal_id'];?>">
<input type="hidden" name="meal-price" value="<?php echo $show_result_row['meal_price'];?>">
<br>
<div>
<legend>Name</legend>
<input type="text" name="order-username" placeholder="Full Name" required>
</div>
<br>
<div>
<legend>Phone</legend>
<input type="text" name="order-phone" placeholder="555-555-5555" required>
</div>
<br>
<div>
<legend>Address</legend>
<input type="text" name="order-address" placeholder="555 N. Main Street" required>
</div>
<br>
<div>
<legend>Quantity (Dozens)</legend>
<input type="text" name="order-count" placeholder="12" required>
</div>
<hr>
<div>
<button class="btn btn-warning btn-lg btn-block" type="submit">Submit Order</button>
</div>
</form>
</div>
<?php include_once 'layout/footer.php'; ?>
You're trying to display an array. You need to loop through the array.
<?php foreach ($show_result_row as $result) { ?>
<div>
<h1><?php echo $result['meal_name'];?></h1>
</div>
<hr>
<div>
<img class="meal-img" id="meal-img" src="<?php echo $result['meal_image'];?>" alt="">
</div>
<?php } ?>
Something like that.
I trying to make a feature, where the user recieves a message saying "Your changes have been saved" after the user has pressed "save changes". When the form is being submittet the page is just refreshed and not redirected to any other page.
I have tried several things but nothing seems to work. I am good at HTML but not PHP. I would love if any of you could help me out!
My code for my profile template is the folowing:
<div class="user-image">
<div class="bordered-image thick-border">
<?php echo get_avatar(ThemexUser::$data['user']['ID'], 200); ?>
</div>
<div class="user-image-uploader">
<form action="<?php echo themex_url(); ?>" enctype="multipart/form-data" method="POST">
<label for="avatar" class="button"><span class="button-icon upload"></span><?php _e('Skift billede','academy'); ?></label>
<input type="file" class="shifted" id="avatar" name="avatar" />
<input type="hidden" name="user_action" value="update_avatar" />
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" />
</form>
</div>
</div>
<div class="user-description">
<form action="<?php echo themex_url(); ?>" class="formatted-form" method="POST">
<div class="message">
<?php ThemexInterface::renderMessages(); ?>
</div>
<div class="sixcol column">
<div class="field-wrapper">
<input type="text" name="first_name" size="30" value="<?php echo ThemexUser::$data['user']['profile']['first_name']; ?>" placeholder="<?php _e('Fornavn','academy'); ?>" />
</div>
</div>
<div class="sixcol column last">
<div class="field-wrapper">
<input type="text" name="last_name" size="30" value="<?php echo ThemexUser::$data['user']['profile']['last_name']; ?>" placeholder="<?php _e('Efternavn','academy'); ?>" />
</div>
</div>
<div class="clear"></div>
<!-- ADRESSE -->
<?php if(!ThemexCore::checkOption('profile_signature')) { ?>
<div class="field-wrapper">
<input type="text" name="signature" value="<?php echo ThemexUser::$data['user']['profile']['signature']; ?>" placeholder="<?php _e('Adresse','academy'); ?>" />
</div>
<?php } ?>
<div class="user-fields">
<?php ThemexForm::renderData('profile', array(), ThemexUser::$data['user']['profile']); ?>
</div>
<?php } ?>
<span class="button-icon save"> </span><?php _e('Gem ændringer','academy'); ?>
<input type="hidden" name="user_action" value="update_profile" />
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" />
</form>
</div>
you are submitting to another url. So you can add something like the below to your functions file to display a message when the url is appended with msg. (you can account for multiple messages using the switch below, look it up) also you will need to add `?msg=yourmessagevariable' to your form action.
add_action('wp_print_scripts', 'notifcation', 100);
function notifcation () {
if($_GET['msg']) {
$message= sanitize_text_field($_GET['msg']);
switch($message) {
case 'reg-business':
$notehead= 'Please register first';
$msg= 'Please register your business before continuing';
break;
case 'nowvalid':
$notehead= "Congratulations";
$msg='You have successfully connected ';
break;
case 'Completed':
$notehead= 'Edited';
$msg='You have successfully edited your advert';
break;
}
?>
<section id="notification" class="notif notif-notice">
<h6 class="notif-title"><?php echo $notehead;?></h6>
<p><?php echo $msg; ?></p>
<div class="notif-controls">
Close
</div>
</section>
<script type="text/javascript">
jQuery(document).ready(function() {
setTimeout(function(){
jQuery('#notification').css('display', 'none');
},3000)
});
jQuery('.notif-close').click(function(e){
e.preventDefault();
jQuery(this).parent().parent().css('display', 'none');
})
</script>
<?php
}
}
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.