How can i do multiple file upload using Drupal 7 Form API? - file-upload

I'd like to upload multiple files using Form API.
'#type' => 'file' provides upload only one file.
$form['picture_upload'] = array(
'#type' => 'file',
'#title' => t(''),
'#size' => 50,
'#description' => t(''),
'#weight' => 5,
);
How can i provide multiple upload?

Aside from putting the form element in a for loop, I would suggest (for now) using the plupload form element.
http://drupal.org/project/plupload
Then:
$form['picture_upload'] = array(
'#type' => 'plupload',
'#title' => t(''),
'#size' => 50,
'#description' => t(''),
'#weight' => 5,
);

This is similar to a issue I had: Drupal 7 retain file upload
You can use managed_file element type instead of file
here's the drupal documentation: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/7#managed_file

Related

PrestaShop save HTML in CustomerMessage->message

I'm making a customization in a PrestaShop 1.6.0.14 where I need to offer an HTML editor when the employee answers to a customer thread. This part I achieved and the I'm getting to send the HTML in the e-mail message.
My problem is to show in the history, I need to show the HTML in the history (sometimes employees send links etc..). To achieve that I need to be able to save HTML in the message field of the customer_message table. When I go to the definition of the ObjectModel (classes/CustomerMessage.php) I see this:
'message' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 65000),
Which is cleaning the HMTL. So I created a new file at override/classes/CustomerMessage.php with this content:
class CustomerMessage extends CustomerMessageCore
{
public function __construct($id = null) {
self::$definition['fields']['message'] = array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 65000);
parent::__construct($id);
}
}
This I believe that would override the property allowing me to save HTML in this field. But it doesn't work. Am I doing it the wrong way? If so, how can I redefine this field?
Thanks for any help
you have to use this settings:
self::$definition['fields']['message'] = array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 65000);
the type should be TYPE_HTML, and don't change validation isCleanHtml because it check about parts of html code that you don't want (like js, script, iframe, etc)
Let me know :)
PS: Every time that we make an override, delete the class_index.php that is stored in cache folder

Pushwoosh notification without sound

How can we send pushnotification without sound using pushwoosh php API
below is my code
pwCall('createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => $podcast_title,
'data' => array('custom' => json_encode($cus_data)),
'link' => 'https://bnc.lt/castbox',
'ios_sound' =>'',
'android_sound' =>'silent.wav',
'platforms'=>array(3),
//'devices'=>array('f82759fc4ca672e27bae0a509710167f52e24577db6d4b5da87e51f8b9ab3b47'),
//'conditions'=>array(array($tag,"EQ",$filter_name)),
)
)
)
);
Thanks
Thanigaivelan
In order to send a push without a sound to iOS devices you should just not specify any sound in 'ios_sound'.
For Android just use the 'android_sound' without a value: 'android_sound'=>''.
Otherwise you can put a soundless file to your app package and play it when you need it.

drupal generate fpdf files

I create website based on drupal 7 with module to generate pdf - i use fpdf library.
I dont know how I can make form to send some data to node where i have php code for generate pdf.
Also i still get error message:
FPDF error: Some data has already been output, can't send PDF file (output started at Z:\xampp\htdocs\domain\includes\common.inc:2748)
where i found:
ob_flush();
when i try change it to
ob_clean()
all nodes generate pdf :/
You can try use other module which is a simple - pdf_using_mpdf
With this module you can get PDF of some node calling www.YOUR_SITE.DOMAIN/node/NID_ID/pdf - where NID_ID is the id of node what you want to render as PDF.
Or also you can use hook_menu() if you need render as PDF only some fields of your node - add your item like
$items['%node/create_pdf'] = array(
'title' => '',
'description' => '',
'page callback' => 'custom_callback_create_pdf',
'page arguments' => array(1),
'access callback' => 'node_access',
'type' => MENU_CALLBACK,
);
Define you callback like
function custom_callback_create_pdf($node) {
// Check if current node has needed field.
if (isset($node->field_my_custom_field_of_node)) {
// Render only field 'field_my_custom_field_of_node';
$view = node_view($node);
$output = render($view['field_my_custom_field_of_node']);
return pdf_using_mpdf_api($output, $node->title);
}
else {
return pdf_using_mpdf_api("<html><body>Current page do not required field.</body></html>", $node->title);
}
}
and print button for download:
$pdf_button = l(t('Download as PDF'), 'node/' . $node->nid . '/create_pdf', array(
'attributes' => array(
'target' => '_blank',
'class' => array('render_as_pdf'),
),
));
echo '<p>' . $pdf_button . '</p>';

How can convert view page into a pdf in Yii

How can convert view page into a pdf in Yii from controller.
in main.php i added this code
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.vendors.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
),
'HTML2PDF' => array(
'librarySourcePath' => 'application.vendors.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
)
),
),
Controller Code is
$mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');
$mPDF1->WriteHTML($this->renderPartial('printformat', array(), true));
$mPDF1->Output();
Error : include(mpdf.php) [function.include]: failed to open stream: No such file or directory
The Error says, you have to include mpdf.php before using it.
You are using YiiPdf Bundle with html2pdf and mpdf.
First download Yii Pdf from here and include in extension as protected/extensions/yii-pdf (ext.yii-pdf as in 'class' => 'ext.yii-pdf.EYiiPdf',). This means your extension folder contains yii-pdf as directory.
Then, download mpdf from here. and place it in vendors as protected/vendors/mpdf as in
'librarySourcePath' => 'application.vendors.mpdf.*',
All explanation is here.

ZendDeveloperTools module not displaying a toolbar in ZF2 beta5

I'm trying to install the ZendDeveloperTools modules for ZF2 beta5. Here are the steps I followed so far:
-Successfully installed ZendSkeletonApplication.
-Downloaded the module into my ./vendor directory.
-Enabled the module in ./config/application.config.php:
<?php
return array(
'modules' => array(
'Application',
'ZendDeveloperTools', // Added this line
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
-Copied ./vendor/ZendDeveloperTools/config/zenddevelopertools.local.php.dist to ./config/autoload/zenddevelopertools.local.php.
-Edited zenddevelopertools.local.php as follows:
<?php
return array(
'zdt' => array(
'profiler' => array(
'enabled' => true,
'strict' => true,
'verbose' => true,
'flush_early' => false,
'cache_dir' => 'data/cache',
'collectors' => array(),
'verbose_listeners' => array('application' => array(
'ZDT_TimeCollectorListener' => true,
'ZDT_MemoryCollectorListener' => true,
))
),
'toolbar' => array(
'enabled' => true,
'auto_hide' => false,
'position' => 'bottom',
'version_check' => false,
'entries' => array(),
),
),
);
-Added define('REQUEST_MICROTIME', microtime(true)); in my ./public/index.php
-Replaced my ./composer.json with the one provided in the ZendDeveloperTools module.
-Removed the , at the end of line 29 which was causing problems (shouldn't be there):
-Ran a composer update :
$ php composer.phar update
Updating dependencies
- Updating zendframework/zendframework (dev-master)
Checking out 9f4dd7f13c8e34362340072d0e2d13efe15e4b1f
Writing lock file
Generating autoload files
-Added error_reporting(E_ALL); ini_set('display_errors', '1'); to ./public/index.php to catch potential errors
When I access my application I don't get any errors (I get the skeleton application home page) but the zend developer toolbar isn't show up
What am I missing to make use of and display the zend developer toolbar?
It was a stupid mistake, I had placed zenddevelopertools.local.php into ./config and not ./config/autoload. Above instructions are correct. Here is what the toolbar looks like for those who are curious:
Worked for me, but one change I had to make for my app was rename the config from:
zenddevelopertools.local.php
to:
zenddevelopertools.local.config.php
Also, I installed BjyProfiler, which "just worked" with my Doctrine2 setup (nice!). The only caveat was that I had to add the default SM factory config so it would stop throwing errors:
'service_manager' => array(
'factories' => array(
/**
* This default Db factory is required so that ZDT
* doesn't throw exceptions, even though we don't use it
*/
'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
$adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array(
'driver' => 'pdo',
'dsn' => 'mysql:dbname=skunk;host=hunk',
'database' => 'bunk',
'username' => 'junk',
'password' => 'punk',
'hostname' => 'lunk',
));
$adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler);
$adapter->injectProfilingStatementPrototype();
return $adapter;
},
),
),
See the screenshot: