Warning: Invalid argument supplied for for each () in Wordpress - arguments

Please Help!! Getting an following Error.
It says something is wrong in 'taxonomy-coupon-store.php, but couldn't find anything wrong?
Warning: Invalid argument supplied for foreach() in /home/searche1/public_html/wp-content/themes/Deals/taxonomy-coupon_store.php
Here is my taxonomy-coupon-store-php file:
ID, 'coupon_store' );
foreach ( $store_obj as $element ) {
$store_id = $element->term_id;
$store_name = $element->name;
$store_description = $element->description;
$store_count = $element->count;
$store_url = get_term_link( $element, 'coupon_store' );
}
$store_url = get_metadata('coupon_store', $store_id, 'junkie_store_url', true);
$store_aff_url = get_metadata('coupon_store', $store_id, 'junkie_store_aff_url', true);
$store_image_preview = junkie_get_store_image_url($store_id, 'term_id', 100);
?>
<header class="page-heading clearfix">
<div class="entry-thumb-wrapper">
<img src="<?php echo $store_image_preview; ?>" class="store-thumbnail" alt="<?php the_title(); ?>" />
</div><!-- .entry-thumb-wrapper -->
<div class="entry-excerpt">
<h1 class="entry-title"><?php echo $store_name; ?></h1>
<p class="store-url"><?php echo $store_url; ?></p>
<p class="store-desc"><?php echo $store_description; ?></p>
</div><!-- .entry-excerpt -->
</header><!-- .page-heading -->
<div class="content-heading clearfix">
<h3><?php _e('Active Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
if ( have_posts() ) :
while(have_posts()) : the_post();
get_template_part( 'content');
endwhile;
else :
get_template_part( 'coupon','none');
endif;
wp_reset_query();
?>
<?php
junkie_pagination();
?>
<div class="content-heading clearfix">
<h3><?php _e('Unreliable Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
$args=array(
'post_type'=>'coupon',
'posts_per_page' => 5,
'post_status' => 'expire',
'orderby' => 'DESC',
'meta_query' => array(
array(
'key' => 'expire_date',
'value' => current_time('mysql'),
'compare' => '<',
'type' => 'DATE'
)
),
'tax_query' => array(
array(
'taxonomy' => 'coupon_store',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$recent = new WP_Query($args);
if ( $recent->have_posts() ) :
while($recent->have_posts()) : $recent->the_post();
get_template_part( 'content');
endwhile;
wp_reset_query();
else :
get_template_part( 'coupon', 'none' );
endif;
?>
</div><!-- #content -->
Please help!

<?php get_header(); ?>
<div id="content" class="content-loop" role="main">
<?php
$taxonomy='coupon_store';
$term = get_queried_object();
//get my store.
$store_obj = get_the_terms( $post->ID, 'coupon_store' );
foreach ( $store_obj as $element ) {
$store_id = $element->term_id;
$store_name = $element->name;
$store_description = $element->description;
$store_count = $element->count;
$store_url = get_term_link( $element, 'coupon_store' );
}
$store_url = get_metadata('coupon_store', $store_id, 'junkie_store_url', true);
$store_aff_url = get_metadata('coupon_store', $store_id, 'junkie_store_aff_url', true);
$store_image_preview = junkie_get_store_image_url($store_id, 'term_id', 100);
?>
<header class="page-heading clearfix">
<div class="entry-thumb-wrapper">
<img src="<?php echo $store_image_preview; ?>" class="store-thumbnail" alt="<?php the_title(); ?>" />
</div><!-- .entry-thumb-wrapper -->
<div class="entry-excerpt">
<h1 class="entry-title"><?php echo $store_name; ?></h1>
<p class="store-url"><?php echo $store_url; ?></p>
<p class="store-desc"><?php echo $store_description; ?></p>
</div><!-- .entry-excerpt -->
</header><!-- .page-heading -->
<div class="content-heading clearfix">
<h3><?php _e('Active Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
if ( have_posts() ) :
while(have_posts()) : the_post();
get_template_part( 'content');
endwhile;
else :
get_template_part( 'coupon','none');
endif;
wp_reset_query();
?>
<?php
junkie_pagination();
?>
<div class="content-heading clearfix">
<h3><?php _e('Unreliable Coupons','junkie'); ?></h3>
</div><!-- .content-heading -->
<?php
$args=array(
'post_type'=>'coupon',
'posts_per_page' => 5,
'post_status' => 'expire',
'orderby' => 'DESC',
'meta_query' => array(
array(
'key' => 'expire_date',
'value' => current_time('mysql'),
'compare' => '<',
'type' => 'DATE'
)
),
'tax_query' => array(
array(
'taxonomy' => 'coupon_store',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$recent = new WP_Query($args);
if ( $recent->have_posts() ) :
while($recent->have_posts()) : $recent->the_post();
get_template_part( 'content');
endwhile;
wp_reset_query();
else :
get_template_part( 'coupon', 'none' );
endif;
?>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Related

How to display all images fields on custom page with post type

I'm trying to loop through the fields of ACF to display all the images of a post type and a specific category
I give a practical example:
I have an ACF image field (image_of_project) and I want to view all the images uploaded in a post type (projects) associated with XYZ category
Now I created this loop:
'
$loop = new WP_Query( array(
'post_type' => 'projects',
'posts_per_page' => 9,
) );
while ( $loop->have_posts() ) : $loop->the_post();
$images = get_field('image_of_project');
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<div class="item">
<a href="<?php echo get_permalink( $post->ID ); ?>" target="_blank">
<?php echo wp_get_attachment_image( $image ); ?>
</a>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
'
The images are displayed but I do not understand why it duplicates me every single image and does not show me only the images of linked to a specific category.
Thanks to anyone who will help me on this mission!
For those interested in the feature, here’s how it worked for me.
function.php
// Loop Gallery Cat1
function my_custom_gallery_cat1() {
query_posts(array(
'post_type' => 'gd_project',
'orderby' => 'rand',
'posts_per_page' => 10,
'tax_query' => array(
array (
'taxonomy' => 'gd_projectcategory',
'field' => 'slug',
'terms' => 'example-terms',
)
),
));
?> <div class="masonry">
<?php
while (have_posts()) : the_post();
$image_field = get_field('image');
$image_url = $image_field['url'];
$image_alt = $image_field['alt']; ?>
<div class="grid-item">
<a href="<?php echo get_permalink( $post->ID ); ?>" target="_blank">
<img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt); ?>" />
<h4><?php the_field( 'title' ); ?></h4>
</a>
</div>
<?php endwhile; ?>
</div> <?php
}
add_shortcode('example-terms', 'my_custom_gallery_cat1');
single-example.php
<div class="container-fluid">
<div class="row">
<?php echo do_shortcode('[categoria]');?>
</div>
</div>

How add create AdditionalActionBlockHtml into massactions in category products grid in magento?

How add create AdditionalActionBlockHtml into massactions in category products grid?
like this status
I founded getAdditionalActionBlockHtml in app/design/adminhtml/default/default/template/widget/grid/massaction.phtml
But I'm dont understand how it's work.
<div class="right">
<div class="entry-edit">
<?php if ($this->getHideFormElement() !== true):?>
<form action="" id="<?php echo $this->getHtmlId() ?>-form" method="post">
<?php endif ?>
<?php echo $this->getBlockHtml('formkey')?>
<fieldset>
<span class="field-row">
<label><?php echo $this->__('Actions') ?></label>
<select id="<?php echo $this->getHtmlId() ?>-select" class="required-entry select absolute-advice local-validation">
<option value=""></option>
<?php foreach($this->getItems() as $_item): ?>
<option value="<?php echo $_item->getId() ?>"<?php echo ($_item->getSelected() ? ' selected="selected"' : '')?>><?php echo $_item->getLabel() ?></option>
<?php endforeach; ?>
</select>
</span>
<span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-hiddens"></span>
<span class="outer-span" id="<?php echo $this->getHtmlId() ?>-form-additional"></span>
<span class="field-row">
<?php echo $this->getApplyButtonHtml() ?>
</span>
</fieldset>
<?php if ($this->getHideFormElement() !== true):?>
</form>
<?php endif ?>
</div>
<div class="no-display">
<?php foreach($this->getItems() as $_item): ?>
<div id="<?php echo $this->getHtmlId() ?>-item-<?php echo $_item->getId() ?>-block">
<?php echo $_item->getAdditionalActionBlockHtml() ?>
</div>
<?php endforeach; ?>
</div>
</div>
I decided this via add methods in massactions
public function addMassAction($observer)
{
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction' && $block->getRequest()->getControllerName() == 'catalog_product')
{
$stores = Mage::getSingleton('adminhtml/system_config_source_store')->toOptionArray();
$block->addItem('export', array(
'label' => Mage::helper("prodestransl")->__("Export"),
'url' => Mage::helper('adminhtml')->getUrl('prod/adminhtml_export/run'),
'additional' => array(
'stores' => array(
'name' => 'stores',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('catalog')->__('Stores'),
'values' => $stores
)
)
));
}
}

shopping cart in codeigniter using ajax

Hi I am new with ajax and having problem. I am trying to make a shopping cart using ajax.I don't know what is wrong with my code please help me out.
When I click the add button an alert comes 'No success' and nothing happen , I am not able add items to cart.
Thanks for helping me.
This is my view
<html>
<head>
<title>Codeigniter cart class</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Raleway:500,600,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css">
<script type="text/javascript">
$(document).ready(function() {
$("#myform").submit(function(event) {
event.preventDefault();
var insert_data= $(this).serializeArray();
$.ajax({
url: "<?php echo base_url(); ?>" + "index.php/shopping2/add",
dataType: 'json',
//type: "POST",
data: insert_data,
success:function(response) {
//if (response){
//var res = JSON.parse(response);
var res = response;
if(res.status == 200){
window.location.href="http://127.0.0.1/codeigniter_cart2/index.php/shopping2";
}else{
alert(res.msg);
}
//}
//else{
// alert('sorry');
//}
}
});
});
});
</script>
</head>
<body>
<div id='content'>
<div class="row">
<div class="col-sm-5">
<h2 align="center">Items</h2>
<?php
?>
<table id="table" border="0" cellpadding="5px" cellspacing="1px">
<?php
foreach ($products as $product) {
$id = $product['serial'];
$name = $product['name'];
$price = $product['price'];
?>
<tr class="well">
<td style="padding-left:15px;"><?php echo $name; ?></td>
<td>
Rs. <?php echo $price; ?></td>
<?php
?>
<?php
echo form_open('',array('id' => 'myform'));
echo form_hidden('id', $id);
echo form_hidden('name', $name);
echo form_hidden('price', $price);
?> <!--</div>-->
<?php
$btn = array(
'class' => 'fg-button teal',
'value' => 'Add',
'name' => 'action',
'id' => 'add_button'
);
?>
<td>
<?php
// Submit Button.
echo form_submit($btn);
echo form_close();
?>
</td>
</tr>
<?php } ?>
</table>
</div>
<div class="col-sm-7">
<!-- <div id="cart" >-->
<h2 align="center">Items on Cart</h2>
<div>
<?php $cart_check = $this->cart->contents();
if(empty($cart_check)) {
echo 'To add products to your shopping cart click on "Add" Button';
} ?> </div>
<table id="table" border="0" cellpadding="5px" cellspacing="1px">
<?php
// All values of cart store in "$cart".
if ($cart = $this->cart->contents()): ?>
<div id="addcart">
<tr id= "main_heading" class="well">
<td style="padding-left:15px;"><?>Name</td>
<td>Price(Rs)</td>
<td>Qty</td>
<td>Amount</td>
<td>Remove</td>
</tr>
<?php
// Create form and send all values in "shopping/update_cart" function.
echo form_open('shopping2/update_cart');
$grand_total = 0;
$i = 1;
foreach ($cart as $item):
echo form_hidden('cart[' . $item['id'] . '][id]', $item['id']);
echo form_hidden('cart[' . $item['id'] . '][rowid]', $item['rowid']);
echo form_hidden('cart[' . $item['id'] . '][name]', $item['name']);
echo form_hidden('cart[' . $item['id'] . '][price]', $item['price']);
echo form_hidden('cart[' . $item['id'] . '][qty]', $item['qty']);
?>
<tr class="well" id="addcart">
<td style="padding-left:15px;">
<?php echo $item['name']; ?>
</td>
<td>
<?php echo number_format($item['price'], 2); ?>
</td>
<td>
<?php echo form_input('cart[' . $item['id'] . '][qty]', $item['qty'], ' type="number" max="99" min="1" value="1" style="width:50px;"'); ?>
</td>
<?php $grand_total = $grand_total + $item['subtotal']; ?>
<td>
Rs <?php echo number_format($item['subtotal'], 2) ?>
</td>
<td>
<?php
// cancle image.
$path = "<img src='http://127.0.0.1/codeigniter_cart2/images/cart_cross.jpg' width='25px' height='20px'>";
echo anchor('shopping/remove/' . $item['rowid'], $path); ?>
</td>
<?php endforeach; ?>
</tr>
<tr>
<td style="padding-left:30px;"><b>Order Total: Rs <?php
//Grand Total.
echo number_format($grand_total, 2); ?></b></td>
<td colspan="5" align="right"><input type="button" class ='fg-button teal' value="Clear cart" onclick="window.location = 'shopping2/remove'">
<?php //submit button. ?>
<input type="submit" class ='fg-button teal' value="Update Cart">
<?php echo form_close(); ?>
</td>
</tr></div>
<?php endif; ?>
</table>
</div>
<!-- <div id="products_e" align="center">-->
<!--</div>-->
<!-- </div>-->
</div>
</div>
</body>
</html>
This is my controller
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Shopping2 extends CI_Controller {
public function __construct()
{
parent::__construct();
//load model
$this->load->model('billing_model');
$this->load->library('cart');
}
public function index()
{
$data['products'] = $this->billing_model->get_all();
$this->load->view('shopping_view2', $data);
}
function add()
{
$insert_data = array(
'id' => $this->input->post('id'),
'name' => $this->input->post('name'),
'price' => $this->input->post('price'),
'qty' => 1
);
$this->cart->insert($insert_data);
//$success = $this->cart->insert($insert_data);
$cart_check = $this->cart->contents();
if(!empty($cart_check)){
//$this->cart->contents(insert_data);
$res = array('status' => 200, 'msg' => 'success');
}else{
$res = array('status' => 500, 'msg' => 'No success');
}
echo json_encode($res);
//echo $data[0]['value'];
//redirect('shopping2');
}
function remove($rowid) {
// Check rowid value.
if ($rowid==="all"){
$this->cart->destroy();
}else{
$data = array(
'rowid' => $rowid,
'qty' => 0
);
$this->cart->update($data);
}
redirect('shopping2');
}
function update_cart(){
// Recieve post values,calcute them and update
$cart_info = $_POST['cart'] ;
foreach( $cart_info as $id => $cart)
{
$rowid = $cart['rowid'];
$price = $cart['price'];
$amount = $price * $cart['qty'];
$qty = $cart['qty'];
$data = array(
'rowid' => $rowid,
'price' => $price,
'amount' => $amount,
'qty' => $qty
);
$this->cart->update($data);
}
redirect('shopping2');
}
}
Please help me how to add items in the cart using ajax.
Since u managed to get a response, the problem should lie in your Model or data insertion.
Few suggestions:
It's also recommended that you use $.post() instead of $.ajax().
"<?php echo base_url(); ?>" + "index.php/shopping2/add" can be changed to "<?php echo site_url('shopping2/add"'); ?>"
Use the built in Codeignter output class to output your JSON. See here: https://www.codeigniter.com/userguide3/libraries/output.html

form validation with array not working

On my form I have some check boxes. And they are in an array. When I submit my form for some reason it clears the Modify check boxes. And then when go back to look not checked.
I have know what's causing issue is $this->form_validation->set_rules('permission[modify]', '', 'callback_modify_check_edit')
It does not seem to like, permission[modify] or permission[modify][] on the set_rules
How am I able to solve this?
Controller Edit Function:
public function edit() {
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'User Group Name', 'required');
$this->form_validation->set_rules('user_group_id', 'User Group Id', 'required');
$this->form_validation->set_rules('permission[modify]', '', 'callback_modify_check_edit');
if ($this->form_validation->run($this) == FALSE) {
$this->getForm();
} else {
$this->load->model('admin/user/model_user_group');
$this->model_user_group->editUserGroup($this->uri->segment(4), $this->input->post());
$this->db->select('permission');
$this->db->from($this->db->dbprefix . 'user_group');
$this->db->where('user_group_id', $this->session->userdata('user_group_id'));
$user_group_query = $this->db->get();
$permissions = unserialize($user_group_query->row('permission'));
$this->session->set_userdata($permissions);
$this->session->set_flashdata('success', 'Congratulations you have successfully modified' .' '. "<strong>" . ucwords(str_replace('_', ' ', $this->router->fetch_class())) .' '. $this->input->post('name') . "</strong>");
redirect('admin/users_group');
}
}
public function modify_check_edit() {
if (!in_array('users_group', $this->session->userdata('modify'))) {
$this->form_validation->set_message('modify_check_edit', 'You do not have permission to edit' );
}
}
View Form:
<?php echo validation_errors('<div class="alert alert-warning text-center"><i class="fa fa-exclamation-triangle"></i>
', '</div>'); ?>
<?php if ($this->uri->segment(4) == FALSE) { ?>
<?php $data = array('class' => 'form-horizontal', 'id' => 'users_group');?>
<?php echo form_open('admin/users_group/add', $data);?>
<?php } else { ?>
<?php $data = array('class' => 'form-horizontal', 'id' => 'users_group');?>
<?php echo form_open('admin/users_group/edit' .'/'. $this->uri->segment(4), $data);?>
<?php } ?>
<div class="form-group">
<?php $data = array('class' => 'col-sm-2 control-label');?>
<?php echo form_label('User Group Name', 'name', $data);?>
<div class="col-sm-10">
<?php
$data_user_name = array(
'id' => 'name',
'name' => 'name',
'class' => 'form-control',
'value' => $name
)
;?>
<?php echo form_input($data_user_name);?>
</div>
</div>
<div class="form-group">
<?php $data = array('class' => 'col-sm-2 control-label');?>
<?php echo form_label('User Group Id', 'user_group_id', $data);?>
<div class="col-sm-10">
<?php
$data_user_group_id = array(
'id' => 'user_group_id',
'name' => 'user_group_id',
'class' => 'form-control',
'value' => $user_group_id
)
;?>
<?php echo form_input($data_user_group_id);?>
</div>
</div>
<div class="form-group">
<?php $data = array('class' => 'col-sm-2 control-label');?>
<?php echo form_label('Access Permission', 'permission_access', $data);?>
<div class="col-sm-10">
<div class="well well-sm" style="height: 200px; overflow: auto;">
<?php foreach ($permissions as $permission) { ?>
<div class="checkbox">
<label>
<?php if (in_array($permission, $access)) { ?>
<?php
$data_checked = array(
'name' => 'permission[access][]',
'id' => 'permission_access',
'value' => $permission,
'checked' => TRUE,
);
echo form_checkbox($data_checked);
?>
<?php echo $permission; ?>
<?php } else { ?>
<?php
$data_not_checked = array(
'name' => 'permission[access][]',
'id' => 'permission_access',
'value' => $permission,
'checked' => FALSE,
);
echo form_checkbox($data_not_checked);
?>
<?php echo $permission; ?>
<?php } ?>
</label>
</div>
<?php } ?>
</div>
<a onclick="$(this).parent().find(':checkbox').prop('checked', true);">Select All</a> / <a onclick="$(this).parent().find(':checkbox').prop('checked', false);">Unselect All</a></div>
</div>
<div class="form-group">
<?php $data = array('class' => 'col-sm-2 control-label');?>
<?php echo form_label('Modify Permission', 'permission_modify', $data);?>
<div class="col-sm-10">
<div class="well well-sm" style="height: 200px; overflow: auto;">
<?php foreach ($permissions as $permission) { ?>
<div class="checkbox">
<label>
<?php if (in_array($permission, $modify)) { ?>
<?php
$data = array(
'name' => 'permission[modify][]',
'id' => 'permission_modify',
'value' => $permission,
'checked' => TRUE,
);
echo form_checkbox($data);
?>
<?php echo $permission; ?>
<?php } else { ?>
<?php
$data = array(
'name' => 'permission[modify][]',
'id' => 'permission_modify',
'value' => $permission,
'checked' => FALSE,
);
echo form_checkbox($data);
?>
<?php echo $permission; ?>
<?php } ?>
</label>
</div>
<?php } ?>
</div>
<a onclick="$(this).parent().find(':checkbox').prop('checked', true);">Select All</a> / <a onclick="$(this).parent().find(':checkbox').prop('checked', false);">Unselect All</a></div>
</div>
<?php echo form_close();?>
After a good half hour trying to figure it out it was mostly part of the call back not to working with th set_rules() for permission[modify]
Just fixed code here for call back and seems to be working now.
public function modify_check_edit() {
$this->load->library('form_validation');
if (is_array($this->session->userdata('modify'))) {
$permission = !in_array('users_group', $this->session->userdata('modify'));
if ($permission) {
$this->form_validation->set_message('modify_check_edit', 'You do not have permission to one' .' '. "<strong>" . ucwords(str_replace('_', ' ', $this->router->fetch_class())) .' '. $this->input->post('name') . "</strong>");
return FALSE;
} else {
return TRUE;
}
return TRUE;
} else {
$this->form_validation->set_message('modify_check_edit', 'You do not have permission to one' .' '. "<strong>" . ucwords(str_replace('_', ' ', $this->router->fetch_class())) .' '. $this->input->post('name') . "</strong>");
return FALSE;
}
}

CakePHP validationErrors empty (validation = true; saveAll = false; validationErrors = null)

Good afternoon.
2 days I have been reading different forums and similar situations regarding the problem that occurs to me, however I have not succeeded in correcting it.
This is my situation:
Order Model
class Order extends AppModel {
public $belongsTo = array("Client", "OrderType");
public $hasMany = array(
'OrderDetail' => array(
'className' => 'OrderDetail',
'foreignKey' => 'order_id',
'counterCache' => true
)
);
public $validate = array(
'client_id' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Favor seleccione un Cliente'
)
),
'date_from' => array(
'required' => array(
'rule' => array('email', 'notEmpty'),
'message' => 'Favor ingresar correo'
)
)
);
}
OrderDetail Model
class OrderDetail extends AppModel {
public $belongsTo = array('Product', 'Smell', 'Order');
public $validate = array(
'product_id' => array(
'required' => true,
'rule' => array('notEmpty'),
'message' => 'Debe ingresar un Producto'
),
'quantity' => array(
'required' => true,
'rule' => array('notEmpty'),
'message' => 'Debe ingresar una Cantidad'
)
);
}
OrdersController Controller
class OrdersController extends AppController {
public function index() {
$this->set('title_for_layout', 'Ordenes');
$this->layout="panel";
}
/* Function para Pruebas */
public function test($mode = null) {
$this->set('title_for_layout', 'Ordenes de Prueba');
$this->layout="panel";
$data = $this->Order->Client->find('list', array('fields' => array('id', 'nombre'), 'order' => array('nombre ASC')));
$this->set('clients', $data);
$data = $this->Order->OrderDetail->Product->find('list', array('fields' => array('id', 'name'), 'order' => array('name ASC')));
$this->set('products', $data);
$data = $this->Order->OrderDetail->Smell->find('list', array('fields' => array('id', 'name'), 'order' => array('name ASC')));
$this->set('smells', $data);
if(is_null($mode)) {
$this -> render('Tests/index');
}
if($mode == 'new') {
$this -> render('Tests/new');
// Guardar Nueva Orden
if ($this->request->is('post')) {
/*
$validates = $this->Order->validates($this->request->data);
debug($validates);
$saved = $this->Order->saveAll($this->request->data);
debug($saved);
debug($this->validationErrors);
*/
if($this->Order->saveAll($this->request->data)) {
$this->Session->setFlash('Nueva Orden Creada', 'flash_success');
return $this->redirect('/orders/test');
} else {
$this->Session->setFlash('La orden no pudo ser creada, favor revise el formulario','default',array('class' => 'alert alert-danger center'));
return $this->redirect('/orders/test/new');
}
}
}
}
/* Function para Servicio */
public function service($mode = null) {
$this->set('title_for_layout', 'Ordenes de Servicio');
$this->layout="panel";
if(is_null($mode)) {
$this -> render('Services/index');
}
if($mode == 'new') {
$this -> render('Services/new');
}
}
/* Function para Retiros */
public function removal($mode = null) {
$this->set('title_for_layout', 'Ordenes de Retiro');
$this->layout="panel";
if(is_null($mode)) {
$this -> render('Removals/index');
}
if($mode == 'new') {
$this -> render('Removals/new');
}
}
}
OrderDetailController Controller
Do not exist (I assumed that I do not need it for this purpose)
Order/Test/new.ctp
<div class="matter">
<div class="container">
<!-- Today status. jQuery Sparkline plugin used. -->
<!-- Today status ends -->
<div class="row">
<div class="col-md-12">
<div class="widget">
<div class="widget-head">
<div class="pull-left">Nueva Orden de Prueba</div>
<div class="clearfix"></div>
</div>
<div class="widget-content">
<div class="padd">
<!-- Content goes here -->
<!-- Flash Message -->
<div class="form-group">
<div class="col-lg-12">
<?php echo $this->Session->flash(); ?>
</div>
</div>
<?php echo $this->Form->create('Order', array('class'=>'form-horizontal', 'novalidate'=>'novalidate')); ?>
<h3>Datos del Cliente</h3>
<div class="widget">
<div class="widget-content">
<div class="padd">
<!-- Cliente y Tipo Orden -->
<div class="form-group">
<label class="control-label col-lg-1">Cliente *</label>
<div class="col-lg-5">
<?php echo $this->Form->input('Order.0.client_id', array('label'=>false, 'class'=>'form-control chosen-select', 'placeholder'=>'Seleccione Cliente', 'type'=>'select','options' => $clients, 'empty' => 'Seleccione Cliente')); ?>
</div>
<div class="col-lg-1">
<?php echo $this->Html->link('Nuevo Cliente', '/clients/add', array('class'=>'btn btn-primary')); ?>
</div>
<?php echo $this->Form->input('Order.0.order_type_id', array('label'=>false, 'class'=>'form-control', 'placeholder'=>'Ingrese Tipo de Orden', 'type'=>'hidden', 'value'=>3)); ?>
</div>
</div>
</div>
</div>
<h3>Vigencia tentativa de la Prueba</h3>
<div class="widget">
<div class="widget-content">
<div class="padd">
<div class="form-group">
<label class="control-label col-lg-1">Desde</label>
<div class="col-lg-2">
<?php echo $this->Form->input('Order.0.date_from', array('label'=>false, 'class'=>'form-control datepicker', 'placeholder'=>'Desde', 'type'=>'text')); ?>
</div>
<label class="control-label col-lg-1">Hasta</label>
<div class="col-lg-2">
<?php echo $this->Form->input('Order.0.date_to', array('label'=>false, 'class'=>'form-control datepicker', 'placeholder'=>'Hasta', 'type'=>'text')); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h3 class="pull-left">Elementos a incorporar en Prueba</h3>
<button type="button" class="btn addRow pull-right btn-primary"><i class="fa fa-plus"></i> Agregar Item</button>
</div>
</div>
<div class="widget">
<div class="widget-content">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>Item</th>
<th>Cantidad</th>
<th>Aroma</th>
<th>Nº Registro</th>
<th width="90px;">Acciones</th>
</tr>
</thead>
<tbody>
<?php for ($i=0;$i<10;$i++) { ?>
<tr>
<td><?php echo $i+1; ?></td>
<td><?php echo $this->Form->input('OrderDetail.'.$i.'.product_id', array('label'=>false, 'class'=>'form-control chosen-select', 'type'=>'select', 'options' => $products, 'empty' => 'Seleccione Item', 'disabled' => 'disabled')); ?></td>
<td><?php echo $this->Form->input('OrderDetail.'.$i.'.quantity', array('label'=>false, 'class'=>'form-control', 'placeholder'=>'Cantidad', 'type'=>'text', 'disabled' => 'disabled')); ?></td>
<td><?php echo $this->Form->input('OrderDetail.'.$i.'.smell_id', array('label'=>false, 'class'=>'form-control chosen-select', 'placeholder'=>'Aromas', 'type'=>'select', 'options' => $smells, 'empty' => 'Seleccione Aroma', 'disabled' => 'disabled')); ?></td>
<td><?php echo $this->Form->input('OrderDetail.'.$i.'.product_number', array('label'=>false, 'class'=>'form-control', 'placeholder'=>'Identificador de Item', 'type'=>'text', 'disabled' => 'disabled')); ?></td>
<td>
<center>
<?php if($i!=0) { ?>
<button type="button" class="btn removeRow btn-xs btn-danger"><i class="fa fa-times"></i> Borrar</button>
<?php } ?>
</center>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<!-- Content ends here -->
</div>
</div>
<div class="widget-foot">
<!-- Botones -->
<div class="form-group">
<div class="col-lg-12">
<?php echo $this->Form->button('Crear Orden', array('class' => array('btn', 'btn-success', 'pull-right'), 'type'=>'submit')); ?>
</div>
</div>
</div>
<?php echo $this->Form->end(); ?>
</div>
</div>
</div>
</div>
</div>
And Now --- The Problem
When I press "Crear Orden" (Save) Button, and Debug this situation I Obtain this...
/app/Controller/OrdersController.php (line 36)
true -> This is debug($this->Order->validates($this->request->data))
/app/Controller/OrdersController.php (line 38)
false -> This is debug($this->Order->saveAll($this->request->data))
/app/Controller/OrdersController.php (line 39)
null -> This is debug($this->validationErrors)
If I enter all correctly, the form is saved successfully. Each field in its respective table, even as a "multiple records".
The problem is that I can not display error messages, because it indicates that the validation is "true"
Please, if you can help me.
Thanks a lot.
Regards,

Resources