This result is a forward only result set, calling rewind() after moving forward is not supported - zend-framework

i want to iterate à table to view tables data 2 time (in listbox and dropdown boutton), when i use one foreach for 1 inout it's ok, but when i use 2 foreach for 2 inputs i hade the bellow error i searched, i found that i must use $resultSet->buffer(); whn i replace it it my table the same eror stay:
File:
C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-db\src\Adapter\Driver\Pdo\Result.php:182
Message:
This result is a forward only result set, calling rewind() after moving forward is not supported
Stack trace:
#0 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-db\src\ResultSet\AbstractResultSet.php(241): Zend\Db\Adapter\Driver\Pdo\Result->rewind()
#1 C:\xampp\htdocs\gestion-commercial-03\module\Documentachat\view\documentachat\documentachat\index.phtml(138): Zend\Db\ResultSet\AbstractResultSet->rewind()
#2 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-view\src\Renderer\PhpRenderer.php(506): include('C:\\xampp\\htdocs...')
#3 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-view\src\View.php(207): Zend\View\Renderer\PhpRenderer->render(NULL)
#4 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-view\src\View.php(236): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#5 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-view\src\View.php(200): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#6 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-mvc\src\View\Http\DefaultRenderingStrategy.php(105): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#7 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#8 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-eventmanager\src\EventManager.php(490): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#9 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-eventmanager\src\EventManager.php(248): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent))
#10 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-mvc\src\Application.php(384): Zend\EventManager\EventManager->triggerEvent(Object(Zend\Mvc\MvcEvent))
#11 C:\xampp\htdocs\gestion-commercial-03\vendor\zendframework\zend-mvc\src\Application.php(356): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#12 C:\xampp\htdocs\gestion-commercial-03\public\index.php(29): Zend\Mvc\Application->run()
#13 {main}
Table :
<?php
///=======================DocumentachatTable factory=========================
namespace Documentachat\Model;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\TableGateway\TableGateway;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
class DocumentachatTable
{
protected $tableGateway;
private $lastinserted;
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function fetchAll($paginated = false)
{
if ($paginated) {
// create a new Select object for the table album
$select = new Select('achat__document');
// create a new result set based on the Album entity
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Documentachat());
// create a new pagination adapter object
$paginatorAdapter = new DbSelect(
// our configured select object
$select,
// the adapter to run it against
$this->tableGateway->getAdapter(),
// the result set to hydrate
$resultSetPrototype->buffer();
$resultSetPrototype
);
$select->where(array('achat__document.deleted' => 1));
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}
$select = $this->tableGateway->getSql()->select();
$select->where(array('achat__document.deleted' => 1));
$results = $this->tableGateway->selectWith($select);
return $results;
}
public function lastInserted()
{
return $this->lastinserted;
}
public function getDocument($id)
{
$id = (int)$id;
$rowset = $this->tableGateway->select(array('id' => $id));
$row = $rowset->current();
if (!$row) {
throw new \Exception("Could not find row $id");
}
return $row;
}
public function getLastCount($idType)
{
$idType = (int)$idType;
$select = $this->tableGateway->getSql()->select();
$select->where->equalTo('id_type', $idType);
$select->order('count desc');
$rowset = $this->tableGateway->selectWith($select);
$row = $rowset->current();
if (!$row) {
return 0;
}
return $row;
}
public function saveDocument(Documentachat $document)
{
$data = array(
'reference' => $document->reference,
'id_type' => $document->idType,
'id_fournisseur' => $document->idFournisseur,
'address' => $document->address,
'deleted' => 1,
'date_doc' => $document->dateDoc
);
$id = (int)$document->id;
if ($id == 0) {
$data['count'] = $this->getLastCount($document->idType)->count + 1;
$this->tableGateway->insert($data);
$this->lastinserted = $this->tableGateway->getLastInsertValue();
} else {
if ($this->getDocument($id)) {
$this->tableGateway->update($data, array('id' => $id));
} else {
throw new \Exception('Documentachat id does not exist');
}
}
}
public function deleteDocument($id)
{
$data = array(
'deleted' => 0,
);
$this->tableGateway->update($data, array('id' => $id));
}
public function searchDocument($query)
{
$select = $this->tableGateway->getSql()->select();
$select->where(array('achat__document.deleted' => 1));
$select->where->like('achat__document.reference', '%' . $query . '%');
$results = $this->tableGateway->selectWith($select);
return $results;
}
View:
<?php
$title = 'Documentachat';
$this->headTitle($title);
?>
<div class="container-fluid container-fullw bg-white ng-scope">
<!-- ======partie haut-->
<div class="panel border-dark panel-white bg-white margin-top-20" style="box-shadow: 0 3px 6px rgb(0 0 0 / 16%), 0 3px 6px rgb(0 0 0 / 23%);">
<div class="panel-body Shadows-2 ">
<!-- =========== inputs filtre-->
<div class="row">
<div class="col-md-2 form-group">
<label> Date début </label>
<input type="date" id="dateMinI" class="form-control" name="dateMinI">
</div>
<div class="col-md-2 form-group">
<label> Date fin </label>
<input type="date" id="dateMaxI" class="form-control" name="dateMaxI" >
</div>
<div class="col-md-2 form-group">
<label> N° Document </label>
<input type="text" id="Reference" class="form-control" name="Reference" value autocomplete="off">
</div>
<div class="col-md-2 form-group">
<label> Fournisseur </label>
<input type="text" id="fournisseur" class="form-control" name="fournisseur" >
</div>
<div class="col-md-2 form-group">
<label> Document Type </label>
<select id="doctype" class="form-control" name="doctype">
<option value="">---</option>
<?php foreach ($this->docTypes as $item) : ?>
<option value=<?php echo $item->id; ?> > <?php echo $item->label; ?> </option>
<?php endforeach;
?>
</select>
</div>
<div class="col-md-2">
<div class=" padding-20">
<button type="button" id="sendid" class="btn btn-primary btn-block">
<i class="fa fa-filter" aria-hidden="true"></i>
OK
</button>
</div>
</div>
</div>
<!-- =========== inpouts filtre-->
<div class="row padding-20 bg-light-grey">
<button type="button" data-toggle="modal" data-target="#transformerModal" id="transformer"
class="btn btn-sm btn-default">
<i class="fa fa-arrow-right" aria-hidden="true"></i>
Transformer
</button>
<div class="btn-group pull-right">
<button type="button " class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Ajouter <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li class="disabled"><a href="#">
<i class=" btn-sm fa fa-file-text-o " aria-hidden="true"></i>
DEVIS</a></li>
<li>
<a target="_blank" href="/document/add/5">
<i class=" btn-light-purple fa fa-file-text-o btn-sm " aria-hidden="true"></i>
BON DE COMMANDE</a>
</li>
<li>
<a target="_blank" href="/document/add/19">
<i class="btn btn-green fa fa-file-text-o btn-sm" aria-hidden="true"></i>
BON DE LIVRAISON</a>
</li>
<li>
<a target="_blank" href="/document/add/20">
<i class=" btn-light-orange fa fa-file-text-o btn-sm " aria-hidden="true"></i>
BON DE RETOUR</a>
</li>
<li class="disabled"><a href="#">
<i class="btn btn-light-azure btn-sm fa fa-file-text-o" aria-hidden="true"></i>
FACTURE INTERNE</a></li>
<li class="disabled"><a href="#">
<i class="btn btn-dark-azure btn-sm fa fa-file-text-o" aria-hidden="true"></i>
FACTURE A COMPTABILISER</a></li>
<li class="disabled"><a href="#">
<i class=" btn-sm fa fa-file-text-o " aria-hidden="true"></i>
FACTURE COMPTABILISEE </a></li>
<li class="disabled"><a href="#">
<i class=" btn-dark-orange btn-sm fa fa-file-text-o " aria-hidden="true"></i>
FACTURE DE RETOUR</a></li>
<li>
<a target="_blank" href="/document/add/33">
<i class=" btn-dark-yellow fa fa-file-text-o btn-sm " aria-hidden="true"></i>
AVOIR FINANCIER</a>
</li>
</ul>
</div>
</div>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Ajouter
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<?php
foreach ($this->docTypes as $item) { ?>
<li><?= $item->label?></li>
<?php } ?>
<?php ?>
</ul>
</div>
</div>
</div>
module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Documentachat\Controller\Documentachat' => 'Documentachat\Controller\DocumentachatController',
'Documentachat\Controller\Parametreachat' => 'Documentachat\Controller\ParametreachatController',
'Documentachat\Controller\DocArticle' => 'Documentachat\Controller\DocArticleController',
),
),
'router' => array(
'routes' => array(
'documentachat' => array(
'type' => 'segment',
'options' => array(
'route' => '/documentachat[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Documentachat\Controller\Documentachat',
'action' => 'index',
),
),
),
'parametreachat' => array(
'type' => 'segment',
'options' => array(
'route' => '/parametreachat[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Documentachat\Controller\Parametreachat',
'action' => 'index',
),
),
),
'docarticle' => array(
'type' => 'segment',
'options' => array(
'route' => '/docarticle[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Documentachat\Controller\DocArticle',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'documentachat' => __DIR__ . '/../view',
),
),
);

Related

Symony: Render a form for each element

I'm trying to render an edit form in a modal for each element on the same page I create them, but it seems not possible to render a same form multiple times.
This is my controller:
/**
* #Route("/outcome", name="outcome")
*/
public function index(OutcomeRepository $repo, Request $request, EntityManagerInterface $manager): Response
{
$outcomes = $repo->findAll();
$outcome = new Outcome();
$form = $this->createForm(OutcomeType::class, $outcome);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$manager->persist($outcome);
$manager->flush();
$this->addFlash(
'success',
"Income <strong>{$outcome->getTitle()}</strong> has been added."
);
return $this->redirectToRoute('outcome');
}
return $this->render('outcome/outcome.html.twig', [
'outcomes' => $outcomes,
'form' => $form->createView(),
]);
}
This is the OutcomeType:
class OutcomeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class, [
'label' => "Title",
'attr' => [
'placeholder' => "Write a title"
]
])
->add('amount', MoneyType::class, [
'label' => "Amount",
'attr' => [
'placeholder' => "Write an amount"
]
])
->add('save', SubmitType::class, [
'label' => 'Send',
'attr' => [
'class' => 'btn btn-primary'
]
]);
}
And this is the twig part:
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#newOutcomeModal">
New outcome
</button>
<div class="modal fade" id="newOutcomeModal" tabindex="-1" aria-labelledby="newOutcomeModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newOutcomeModal">Add a new outcome</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{{form_start(form)}}
{{form_widget(form)}}
{{form_end(form)}}
</div>
</div>
</div>
</div>
{% for outcome in outcomes %}
<div class="card m-4">
<div class="card-body">
<h5 class="card-title">{{outcome.title}}</h5>
<p class="card-text">{{outcome.amount}}</p>
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#editOutcomeModal{{outcome.id}}">Edit</button>
</div>
</div>
<div class="modal fade" id="editOutcomeModal{{outcome.id}}" tabindex="-1" aria-labelledby="editOutcomeModal{{outcome.id}}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editOutcomeModal{{outcome.id}}">Edit {{outcome.title}} outcome</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{{form_start(form)}}
{{form_widget(form)}}
{{form_end(form)}}
</div>
</div>
</div>
</div>
{% endfor %}
I get the error: "An exception has been thrown during the rendering of a template ("Field "outcome" has already been rendered, save the result of previous render call to a variable and output that instead.")."
I don't know how to solve this. I tried to turn the fields of OutcomeType in a collectionType but it didn't work.
Can someone help me please ?

Symfony - Form is not submit

I work with Symfony to build and send a contact form by mail.
I use swiftMailer.
The problem is that my form is not submitted.
So, my swiftmailer can't work because the isSumbitted will stay at false and $mailer->send(message) will not be activate
My controller :
public function index (Request $request, Swift_Mailer $mailer)
{
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$contactData = $form->getData();
$name = $contactData['name'];
$content = $contactData['message'];
$email = $contactData['email'];
$entreprise = $contactData['entreprise'];
$zip = $contactData['zip'];
$message = (new Swift_Message('Vous avez un nouveau message sur le site AMC Industrie.fr'))
->setFrom('test#example.com')
->setTo('test#gmail.com')
->setSubject('Demande d\'information')
->setCharset('utf-8')
->setContentType('text/html')
->setBody(
"
<p> Vous avez reçu un message de <strong>$name</strong>, de l'entreprise <strong>$entreprise</strong>
<br>(code postal : $zip ) <br>
Son email est : <strong>$email</strong>. </p>
<p> Son message :</p>
<p>$content
</p>
"
)
;
$mailer->send($message);
return $this->redirectToRoute('map_contact');
}
return $this->render('contact/map_contact.html.twig', [
'form' => $form->createView()
]);
}
My Form :
{
$builder
->add('name',TextType::class,
['label'=>false,
'constraints' => new NotBlank,
'attr' => [
'class'=> 'form-control',
'placeholder' => 'Nom et prénom',
]
])
->add('email',EmailType::class,
['label'=>false,
'constraints' => new NotBlank,
'attr' => [
'class' => 'form-control',
'placeholder' => 'adresse e-mail'
]
])
->add('entreprise',TextType::class,
['label'=>false,
'constraints' => new NotBlank,
'attr' => [
'class'=> 'form-control',
'placeholder' => 'Nom de votre entreprise'
]
])
->add('zip',NumberType::class,
['label'=>false,
'constraints' => new NotBlank,
'attr' => [
'class'=> 'form-control',
'placeholder' => 'Code postal'
]
])
->add('message',TextareaType::class,
['label'=>false,
'constraints' => new NotBlank,
'attr' => [
'class'=> 'form-control',
'placeholder' => 'Décrivez-nous votre projet'
]
])
->add('save', SubmitType::class,
['label' => 'Envoyer',
'attr'=> [
//'class' => 'waves-effect waves-light btn-large btn btn-primary mt-1 mb-5 lift',
'id' => 'form-submit'
]])
;
}
My template :
<form>
{{ form_start(form) }}
<div class="row">
<div class="col-12 col-md-6">
<div class="form-group mb-5">
{{form_label(form.name, 'Nom et prénom')}}
{{form_widget(form.name)}}
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group mb-5">
{{form_label(form.email, 'Email') }}
{{form_widget(form.email)}}
</div>
<div class="col-12 col-md-6">
<div class="form-group mb-5">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<div class="form-group mb-5">
{{form_label(form.entreprise, 'Entreprise')}}
{{form_widget(form.entreprise)}}
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group mb-5">
{{form_label(form.zip, 'Code Postal')}}
{{form_widget(form.zip)}}
</div>
<div class="col-12 col-md-6">
<div class="form-group mb-5">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="form-group">
{{form_label(form.message, 'Comment pouvons-nous vous aider ?')}}
{{form_widget(form.message)}}
</div>
</div>
</div> <!-- / .row -->
<div class="row justify-content-center">
<div class="col-auto py-5">
<!-- Submit -->
<div>
{{form_widget(form.save)}}
</div>
</div>
</div>
{{ form_end(form) }}
</form>
My debug tool :
Form in get parameter OK. I have all my input with informations.
Debug tool - get parameters:
BUT
there is not sumbitted data. form is not submit
debug tool - form is not submit:
I don't understand where is my problem.
Ok, it's resolved !
The problem : I already have a html balise for my form, in my template.
When I delete , it's ok !

Add div around input field in ZF2 form

I am creating a form with Zend Framework 2. I'm using Form class to define form elements like this:
class PropertyForm extends Form
{
public function __construct($name=null)
{
...
$this->add(array(
'name' => 'zip',
'type' => 'Text',
'required' => false,
'options' => array(
'label' => 'Zip Code',
),
'attributes' => array(
'id' => 'zip',
'class' => 'form-control',
),
));
...
}
}
And in view I display this form element with the following code:
<div class="form-group"><?php echo $this->formRow($form->get('zip')); ?></div>
This generates the following HTML output:
<div class="form-group">
<label for="zip">Zip Code</label>
<input type="text" name="zip" id="zip" class="form-control" value="">
</div>
What I want to achieve is to have <div class="my-class"> around the input field as well. So the desired HTML output would be:
<div class="form-group">
<label for="zip">Zip Code</label>
<div class="my-class">
<input type="text" name="zip" id="zip" class="form-control" value="">
</div>
</div>
How can I achieve that?
You could get label and the element itself with two different calls:
For label:
<?php echo $this->formLabel($yourForm->get('your_element')); ?>
For the elements:
<?php echo $this->formSelect($yourForm->get('your_element_select')); ?>
<?php echo $this->formText($yourForm->get('your_element_text')); ?>
<?php echo $this->formRadio($yourForm->get('your_element_radio')); ?>
So, for you example, it would be something like:
<div class="form-group">
<?php echo $this->formLabel($form->get('zip')); ?>
<div class="my-class">
<?php echo $this->formText($form->get('zip')); ?>
</div>
</div>

Cakephp form is not being submitted

I am using cakephp2.2.7 I have already done a lot of form submission maintaining cakephp standard. Here I have multiple form based on loop iteration. Here is my code:
<style type="text/css">
.alert {
padding: 6px;
margin-bottom: 5px;
border: 1px solid transparent;
border-radius: 4px;
text-align: center;
}
input#OrderProductPieces {
display: inline;
float: l;
width: 50px;
}
th,td{
text-align: center;
}
</style>
<div class="page-content-wrapper">
<div class="page-content">
<!-- BEGIN PAGE HEADER-->
<h3 class="page-title">
Edit this order <small>Edit can't be performed when it delivered</small>
</h3>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<div class="row">
<div class="col-md-12">
<!-- BEGIN EXAMPLE TABLE PORTLET-->
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-phone"></i>Edit Order
</div>
<?php echo $this->Session->flash(); ?>
<div class="tools">
<a href="javascript:;" class="reload">
</a>
</div>
</div>
<div class="portlet-body">
<table class="table table-striped table-hover table-bordered" id="sample_editable_1">
<thead>
<tr>
<th>Product Info </th>
<th>Customer Info</th>
<th > Action</th>
</tr>
</thead>
<tbody>
<?php
$order = $datas['orders'];
$customer = $datas['customers'];
$order_products = $datas['order_products'];
$product = $datas['products'];
$psettings = $datas['psettings'];
// pr($datas);
// exit;
foreach ($datas['products'] as $index => $product):
echo $this->Form->create('OrderProduct', array(
'inputDefaults' => array(
'label' => false,
'div' => false
),
'class' => 'form-horizontal',
'novalidate' => 'novalidate',
)
);
?>
<tr >
<td>
<img src="<?php echo $this->webroot . 'productImages/small/' . $psettings[$index]['small_img'] ?>" width="37" height="34">
<span class="cart-content-count">x <?php
echo $this->Form->input(
'pieces', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $order_products[$index]['pieces']
)
);
?>
</span>
<span>
<?php echo $product['name'] . ' By ' . $product['writer']; ?>
</span>
</td>
<?php
if ($index == 0):
?>
<td>
<?php
echo $this->Form->input(
'Customer.name', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $customer['name']
)
);
?>
<?php
echo $this->Form->input(
'Customer.city', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $datas['city']['name']
)
);
?>
<?php
echo $this->Form->input(
'Customer.location', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $datas['location']['name']
)
);
?>
<?php
echo $this->Form->input(
'Customer.mobile', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $customer['mobile']
)
);
?>
<?php
echo $this->Form->input(
'Customer.alt_mobile', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $customer['alt_mobile']
)
);
?>
</td>
<?php
else:
?>
<td> <strong>Same as Above</strong> </td>
<?php
endif;
?>
<?php
echo $this->Form->input(
'Customer.id', array(
'type' => 'hidden',
'value' => $customer['id']
)
);
?>
<?php
echo $this->Form->input(
'Customer.id', array(
'type' => 'hidden',
'value' => $customer['id']
)
);
?>
<?php
echo $this->Form->input(
'OrderProduct.id', array(
'type' => 'hidden',
'value' => $datas['order_products'][$index]['id']
)
);
?>
<td >
<div class="controls center">
<div class="form-actions">
<div class="row">
<div class="col-md-4">
<?php
echo $this->Form->button(
'Save Changes', array('class' => 'btn green', 'type' => 'submit')
);
?>
</div>
<div class="col-md-4">
<?php
echo $this->Form->button(
'Delete', array('class' => 'btn btn-danger', 'type' => 'submit')
);
?>
</div>
<div class="col-md-4">
<?php
echo $this->Form->button(
'Add New', array('class' => 'btn green', 'type' => 'submit')
);
?>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php
echo $this->Form->end();
endforeach;
?>
</tbody>
</table>
</div>
</div>
<!-- END EXAMPLE TABLE PORTLET-->
</div>
</div>
<!-- END PAGE CONTENT -->
</div>
</div>
<!-- END CONTENT -->
But when I click on save changes, delete or add new button form is not being submitted. I may missed a very basic issue but not found by myself. Any help will be appreciated.
you must give each submit button a name attribute.
Try this code below:
<style type="text/css">
.alert {
padding: 6px;
margin-bottom: 5px;
border: 1px solid transparent;
border-radius: 4px;
text-align: center;
}
input#OrderProductPieces {
display: inline;
float: l;
width: 50px;
}
th,td{
text-align: center;
}
</style>
<div class="page-content-wrapper">
<div class="page-content">
<!-- BEGIN PAGE HEADER-->
<h3 class="page-title">
Edit this order <small>Edit can't be performed when it delivered</small>
</h3>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<div class="row">
<div class="col-md-12">
<!-- BEGIN EXAMPLE TABLE PORTLET-->
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-phone"></i>Edit Order
</div>
<?php echo $this->Session->flash(); ?>
<div class="tools">
<a href="javascript:;" class="reload">
</a>
</div>
</div>
<div class="portlet-body">
<table class="table table-striped table-hover table-bordered" id="sample_editable_1">
<thead>
<tr>
<th>Product Info </th>
<th>Customer Info</th>
<th > Action</th>
</tr>
</thead>
<tbody>
<?php
$order = $datas['orders'];
$customer = $datas['customers'];
$order_products = $datas['order_products'];
$product = $datas['products'];
$psettings = $datas['psettings'];
// pr($datas);
// exit;
foreach ($datas['products'] as $index => $product):
echo $this->Form->create('OrderProduct', array(
'inputDefaults' => array(
'label' => false,
'div' => false
),
'class' => 'form-horizontal',
'novalidate' => 'novalidate',
)
);
?>
<tr >
<td>
<img src="<?php echo $this->webroot . 'productImages/small/' . $psettings[$index]['small_img'] ?>" width="37" height="34">
<span class="cart-content-count">x <?php
echo $this->Form->input(
'pieces', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $order_products[$index]['pieces']
)
);
?>
</span>
<span>
<?php echo $product['name'] . ' By ' . $product['writer']; ?>
</span>
</td>
<?php
if ($index == 0):
?>
<td>
<?php
echo $this->Form->input(
'Customer.name', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $customer['name']
)
);
?>
<?php
echo $this->Form->input(
'Customer.city', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $datas['city']['name']
)
);
?>
<?php
echo $this->Form->input(
'Customer.location', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $datas['location']['name']
)
);
?>
<?php
echo $this->Form->input(
'Customer.mobile', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $customer['mobile']
)
);
?>
<?php
echo $this->Form->input(
'Customer.alt_mobile', array(
'class' => 'form-control ',
'type' => 'text',
'value' => $customer['alt_mobile']
)
);
?>
</td>
<?php
else:
?>
<td> <strong>Same as Above</strong> </td>
<?php
endif;
?>
<?php
echo $this->Form->input(
'Customer.id', array(
'type' => 'hidden',
'value' => $customer['id']
)
);
?>
<?php
echo $this->Form->input(
'Customer.id', array(
'type' => 'hidden',
'value' => $customer['id']
)
);
?>
<?php
echo $this->Form->input(
'OrderProduct.id', array(
'type' => 'hidden',
'value' => $datas['order_products'][$index]['id']
)
);
?>
<td >
<div class="controls center">
<div class="form-actions">
<div class="row">
<div class="col-md-4">
<?php
echo $this->Form->button(
'Save Changes', array('class' => 'btn green', 'name'=>'save', 'type' => 'submit')
);
?>
</div>
<div class="col-md-4">
<?php
echo $this->Form->button(
'Delete', array('class' => 'btn btn-danger', 'name'=>'delete','type' => 'submit')
);
?>
</div>
<div class="col-md-4">
<?php
echo $this->Form->button(
'Add New', array('class' => 'btn green','name'=>'add','type' => 'submit')
);
?>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php
echo $this->Form->end();
endforeach;
?>
</tbody>
</table>
</div>
</div>
<!-- END EXAMPLE TABLE PORTLET-->
</div>
</div>
<!-- END PAGE CONTENT -->
</div>
</div>
<!-- END CONTENT -->
while at your controller you could check which button is clicked like this:
if(isset($this->request->data['OrderProduct']['save'])){
}
if(isset($this->request->data['OrderProduct']['delete'])){
}
if(isset($this->request->data['OrderProduct']['add'])){
}
Hope this help.

Zend Form Decorators issue

*I speak English not well. So i'm going to post the code now.*
Form code:
protected $elementDecorators = array('ViewHelper','Errors','Description','Label',
array('HtmlTag',array('tag' => 'div','class' => '_wrapperElement')
));
public function init(){
$this->addElement('text','mytext',array(
'class' => '_inputText',
'label' => 'Mytext',
'required' => true,
'decorators' => $this->elementDecorators
));
$this->setDecorators(array('FormElements',array('HtmlTag',array('tag' => 'div','class' => '_formWrapper')),'Form'));
}
Output:
<form method="post" action="" enctype="application/x-www-form-urlencoded">
<div class="_formWrapper">
<div class="_wrapperElement">
<label class="required" for="mytext">Mytext</label>
<input type="text" class="_inputText" value="" id="mytext" name="mytext">
</div>
</div>
</form>
Now i want a div wraps Label and Input element like this:
<form method="post" action="" enctype="application/x-www-form-urlencoded">
<div class="_formWrapper">
<div class="_wrapperElement">
<div class="_wrapperLabel">
<label class="required" for="mytext">Mytext</label>
</div>
<div class="_wrapperInput">
<input type="text" class="_inputText" value="" id="mytext" name="mytext">
</div>
</div>
</div>
</form>
How to do that?
I tried many times but i can't do it.
Thanks!
protected $elementDecorators = array('ViewHelper','Errors','Description', array('Label', array('tag' => 'div', 'class' => '_wrapperLabel')
),
array('HtmlTag',array('tag' => 'div','class' => '_wrapperInput')
));
i found the solution that render decorators to ViewScript.