TYPO3 - Extbase Custom query w/ QueryBuilder: How to add action show to url for links to work again - typo3

When run I this query ... there is no show action in the links in my list view ... and they do not work anymore:
Controller.php
$uid = 10;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$statement = $queryBuilder
->select('uid', 'pid', 'header')
->from('tt_content')
->where(
$queryBuilder->expr()->eq('uid', $uid)
)
->execute();
while ($row = $statement->fetchAll()) {
$this->view->assign('inet', $row);
}
Console:
<tr id="2">
<td>2</td>
<td class="name">Company Name Inc</td>
</tr>
When I debug it I can see that I render the following array:
array(20 items)
0 => array(3 items)
uid => 1 (integer)
code => '213800' (6 chars)
name => 'Company Name Inc' (16 chars)
How can I get the links to work again?

change
<f:link.action action="show" pageUid="43" arguments="{record:record}">{record.name}</f:link.action>
to
<f:link.action action="show" pageUid="43" arguments="{record:record.uid}">{record.name}</f:link.action>
because you ain't getting Objects anymore but arrays of database rows.
Additionally your listAction is missing the parameters $minUid and $maxUid.

Related

Drop down does not show the option in correct format selected in codeigniter

<datalist id="stoplist">
Array
(
[0] => Array
(
[stops] => katraj dairy
)
[1] => Array
(
[stops] => bharati vidyapith
)
[2] => Array
(
[stops] => balaji nagar
)
[4] => Array
(
[stops] => k k market
)
)
</datalist>
This is my view
foreach ($data1 as $row) {
echo "<option value=".$row['stops'].">".$row['stops']."</option>";
}
When I select katraj dairy I get only katraj as a value.
I am getting correct value from database as I print above. What is the problem?
From your controller you need to pass data from your controller before you can access it from your view.
&this->load->view("viewname.php",$data)
Where $data is the array you get from your database
format for select option
<select>
<option value="">name</option>
</select>
Modified code:
echo "<select>";
foreach ($data1 as $row) {
echo "<option value=".$row['stops'].">".$row['stops']."</option>";
}
echo "</select>";

How to get List for Contact Form 7

I have 2 contact forms created by Contact Form 7.
How to list all contact forms created through shortcode?
Please check images, tks.
Updated:
this is my code, this working!
$args = array('post_type' => 'wpcf7_contact_form', 'posts_per_page' => -1);
$rs = array();
if( $data = get_posts($args)){
foreach($data as $key){
$rs[$key->ID] = $key->post_title;
}
}else{
$rs['0'] = esc_html__('No Contact Form found', 'text-domanin');
}
Below is a dropdown list:
<select name="field-name" id="field-id">
<option value="">--Select--</option><?php
$dbValue = get_option('field-name'); //example!
$posts = get_posts(array(
'post_type' => 'wpcf7_contact_form',
'numberposts' => -1
));
foreach ( $posts as $p ) {
echo '<option value="'.$p->ID.'"'.selected($p->ID,$dbValue,false).'>'.$p->post_title.' ('.$p->ID.')</option>';
} ?>
</select>

Prestashop 1.6 add product's manufacturer name in mail template

I'd like to add the product's manufacturer name in the new order e-mail. Customer side and admin side.
So, I'd tried to edit the /mails/fr/order_conf_product_list.tpl file to add a new cell with
{$product['manufacturer_name']}
but with no chance.
I already tried severals tips from the forum like the following but the cell stayed empty...
https://www.prestash...turer-reference
Any help will be appreciate.
Thank you very much.
To realize this operation, you need before add the variable manufacturer
For your test you can edit the file [your_shop]/classes/PaymentModule.php(but the better solution is to use override):
1 - Keep manufacturer object
2 - add the manufacturer object in product_var_tpl
foreach ($order->product_list as $product) {
$manufacturer = new Manufacturer((int)$product['id_manufacturer']);
****
$product_var_tpl = array(
'manufacturer' => $manufacturer,
'reference' => $product['reference'],
'name' => $product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : ''),
'unit_price' => Tools::displayPrice($product_price, $this->context->currency, false),
'price' => Tools::displayPrice($product_price * $product['quantity'], $this->context->currency, false),
'quantity' => $product['quantity'],
'customization' => array()
);
}
And in your file /mails/fr/order_conf_product_list.tpl
you can use the object 'manufacturer'
{$product['manufacturer']->name}
The solution to get the manufacturer's name on the customer mail was, as #timactive wrote, to edit the PaymentModule.php.
So, to get the manufacturer's name in the customers mails :
PaymentModule.php :
foreach ($order->product_list as $product) {
$manufacturer = new Manufacturer((int)$product['id_manufacturer']);
$product_var_tpl = array(
'reference' => $product['reference'],
'name' => $product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : ''),
'unit_price' => Tools::displayPrice($product_price, $this->context->currency, false),
'price' => Tools::displayPrice($product_price * $product['quantity'], $this->context->currency, false),
'quantity' => $product['quantity'],
'customization' => array(),
'manufacturer' => $manufacturer->name
);
And than in the order_conf_product_list.html, call the product object like this :
{$product['manufacturer']}
It's a part of the solution because I want to add manufacturer's name on the admin new order mail too.
Add manufacturer's name on the admin new order mail :
To complete this, I had to edit the MailAlert module like this :
In mailalert.php, in the function "hookActionValidateOrder" :
foreach ($products as $key => $product)
{
$manufacturer = new Manufacturer($product['id_manufacturer'], $id_lang);
$items_table .=
'<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
<td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td>
<td style="padding:0.6em 0.4em;">'.$manufacturer->name.'</td>
<td style="padding:0.6em 0.4em;">
<strong>'.$product['product_name'].''
.(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '')
.(!empty($customization_text) ? '<br />'.$customization_text : '')
.'</strong>
</td>
<td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td>
<td style="padding:0.6em 0.4em; text-align:center;">'.(int)$product['product_quantity'].'</td>
<td style="padding:0.6em 0.4em; text-align:right;">'
.Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false)
.'</td>
</tr>';
And now, to create to cell, go to mailalert/mails/fr/new-order.html and add this line around the line 114 :
<th style="border:1px solid #D6D4D4;background-color:#fbfbfb;font-family:Arial;color:#333;font-size:13px;padding:10px">Marque</th>

Jquery File Upload add extra upload fields

I'm using Jquery-File-Upload for my upload page, and I'm having a problem to add extra upload fields.
I'm following that page: https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-submit-additional-form-data
It works well for 1 file submission.
However, with multiple files submission we are starting to see issues, because files are uploaded 1 file / POST (singleFileUploads: true).
The code I'm using as reference is the following:
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<!-- ... -->
<td class="title"><label>Title: <input name="title[]" required></label></td>
<!-- ... -->
</tr>
{% } %}
</script>
If you submit that with 2 files, then you get 2 POSTS:
1/
$_REQUEST:
(
title:
(
[0] -> Title1
[1] -> Title2
)
)
$_FILES:
(
[0] -> ( 'name' => 'file name 1', ... )
)
2/
$_REQUEST:
(
title:
(
[0] -> Title1
[1] -> Title2
)
)
$_FILES:
(
[0] -> ( 'name' => 'file name 2', ... )
)
Then, on php side, the function handle_form_data relies on file index
<?php
// ...
protected function handle_form_data($file, $index) {
// Handle form data, e.g. $_REQUEST['description'][$index]
}
// ...
The problem is that index is always 0, because we're uploading 1 file / post. Now you see that since the $_REQUEST uploads all extra fields from all files (no matter what is it the current file), the index from $_FILES gets de-synchronized from the extra fields array.
Do you know any workaround, except turning singleFileUploads to OFF?
Ok, I will answer myself.
First, we will attribute an id to the files as soon as they are added to the UI. We maintain an incremental index for that:
//global
var current_file_index = 0;
Next, we need to play with fileuploadadd callback to add that index to the files:
$('#fileupload').bind('fileuploadadd', function (e, data) {
for (var i = 0; i < data.files.length; i++) {
data.files[i].index = current_file_index++;
}
});
That index is now accessible when adding the files on UI side. We don't want the custom input to be added to the form, so change the name by an id (so that it will not be submitted). And add the brand new index as part of that ID:
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<!-- ... -->
<td class="title"><label>Title: <input id="title_{%=file.index%}" required></label></td>
<!-- ... -->
</tr>
{% } %}
</script>
Then, when we submit the file(s), we want to add the result of that input to the formData. We don't care about sending to much data, so we basically send the whole files array as JSON string:
$('#fileupload').bind('fileuploadsubmit', function (e, data) {
for (var i = 0; i < data.files.length; i++) {
var title = $("title_ + data.files[i].index.toString()").val();
data.files[i].title = title;
}
data.formData = {
files_data: JSON.stringify(data.files)
}
});
Don't forget the get the data back on server side in $_REQUEST["files_data"], and explode the json that now contains only 1 file's data).
I know, it's too late, but i use easiest way:
<input type="text" name="{%=file.name%}[title]">
<input type="text" name="{%=file.name%}[description]">
Then you get convenient data array for each file by filename, like this:
print_r($_POST);
/* will be:
* Array
* (
* [file1_jpg] => Array
* (
* [title] => title 1
* [description] => description 1
* )
*
* [file2_jpg] => Array
* (
* [title] => title 2
* [description] => description 2
* )
*
* [file3_png] => Array
* (
* [title] => title 3
* [description] => description 3
* )
*
* )
*/
But remember: all dots in $_POST keys will be replaced to underscores! This is normal. Just remember it.
Late to answer as well, but I just got done working through the same issue.
There is a key part of the documentation linked above that the OP didn't implement:
$('#fileupload').bind('fileuploadsubmit', function (e, data) {
var inputs = data.context.find(':input');
if (inputs.filter(function () {
return !this.value && $(this).prop('required');
}).first().focus().length) {
data.context.find('button').prop('disabled', false);
return false;
}
data.formData = inputs.serializeArray();
});
With this added, the "closest" value for the input field is added to the formData array that is submitted with the form.
More details at: https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-submit-additional-form-data#setting-formdata-on-upload-start-for-each-individual-file-upload

Symfony 2 This form should not contain extra fields

I created a form using formBuilder in Symfony. I add some basic styling to the form inputs using an external stylesheet and referencing the tag id. The form renders correctly and processes information correctly.
However, it outputs an unwanted unordered list with a list item containing the following text: This form should not contain extra fields.
I am having a really hard time getting rid of this notice. I was wondering if someone can help me understand why it being rendered with my form and how to remove it?
Many thanks in advance!
Controller
$form = $this->createFormBuilder($search)
->add('searchinput', 'text', array('label'=>false, 'required' =>false))
->add('search', 'submit')
->getForm();
$form->handleRequest($request);
Twig Output (form is outputted and processed correctly
This form should not contain extra fields.
Rendered HTML
<form method="post" action="">
<div id="form">
<ul>
<li>This form should not contain extra fields.</li>
</ul>
<div>
<input type="text" id="form_searchinput" name="form[searchinput]" />
</div>
<div>
<button type="submit" id="form_search" name="form[search]">Search</button>
</div>
<input type="hidden" id="form__token" name="form[_token]" value="bb342d7ef928e984713d8cf3eda9a63440f973f2" />
</div>
</form>
It seems to me that you have the problem because of the token field. If it is so, try to add options to createFormBuilder():
$this->createFormBuilder($search, array(
'csrf_protection' => true,
'csrf_field_name' => '_token',
))
->add('searchinput', 'text', array('label'=>false, 'required' =>false))
->add('search', 'submit')
->getForm();
To find out the extra field use this code in controller, where you get the request:
$data = $request->request->all();
print("REQUEST DATA<br/>");
foreach ($data as $k => $d) {
print("$k: <pre>"); print_r($d); print("</pre>");
}
$children = $form->all();
print("<br/>FORM CHILDREN<br/>");
foreach ($children as $ch) {
print($ch->getName() . "<br/>");
}
$data = array_diff_key($data, $children);
//$data contains now extra fields
print("<br/>DIFF DATA<br/>");
foreach ($data as $k => $d) {
print("$k: <pre>"); print_r($d); print("</pre>");
}
$form->bind($data);
This message is also possible if you added/changed fields in your createFormBuilder() and press refresh in your browser...
In this case it's ok after sending the form again ;-)
I got the same message while having multiple forms on the same page. Turns out, symfony defaults to the name 'form' for all of them. Instead of using createFormBuilder, you can change the name of the form to avoid conflicts using
public FormBuilderInterface createNamedBuilder(string $name, string|FormTypeInterface $type = 'form', mixed $data = null, array $options = array(), FormBuilderInterface $parent = null)
See https://stackoverflow.com/a/13366086/1025437 for an example.
I ran into this error when creating a multi-step form.
When the step 1 form is submitted, $request->request contains acme_mybundle_myform array. This created a validation error and stopped the back, forward and form fields from populating correctly. Not to mention "this-form-should-not-contain-extra-fields"
I discovered this thanks to the code by nni6.
The solution in my case was inside the controller:
if ($form->isValid())
{
if($form->has('nextStep') && $form->get('nextStep')->isClicked())
{
$session->getFlashBag()->set('notice', 'Next clicked');
$registerType->incrementStep();
$request->request->remove('acme_mybundle_myform');
return $this->forward("AcmeMyBundle:Default:register", array($request));
}
....
}
I had the same error.
It was because I had a form which, by mistake, had a NULL name.
In the HTML, the name attribute would look like this:
<form name href="..." action"..."></form>
As simple as that.
Might not be the case for everyone, but worth to check.