Gravity forms repeater with upload file error - repeater

I'm building a form with a repeater and a file upload inside. When I submit the form, the input file filed always give me the error: There was an error while uploading the file. Error code: 1
Add
Here's my code:
$uploadfiles = GF_Fields::create( array(
'type' => 'fileupload',
'id' => 1006, // The Field ID must be unique on the form
'formId' => $form['id'],
'multipleFiles' => false,
'allowedExtensions' => 'gif,jpg,jpeg,png,txt,rtf,pdf,doc,docx,odt,ppt,pptx,odp,xls,xlsx,ods,xml',
'description' => '<br>Relevant documents: our transport way bill, probill, photos, etc.<br>Files must be less than 2 MB.<br>Allowed extensions: gif jpg jpeg png txt rtf pdf doc docx odt ppt pptx odp xls xlsx ods xml.',
'label' => __('Please attach any relevant document', 'srx'),
'pageNumber' => 1, // Ensure this is correct
));
// Create a repeater for the team members and add the name and email fields as the fields to display inside the repeater.
$team = GF_Fields::create( array(
'type' => 'repeater',
'description' => '',
'id' => 1000, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => __('Products', 'srx'),
'addButtonText' => __('Add product', 'srx'),
'removeButtonText' => __('Remove product', 'srx'),
'maxItems' => 100, // Optional
'pageNumber' => 1, // Ensure this is correct
'fields' => array( $reference, $quantity, $product, $lista, $uploadfiles ), // Add the fields here.
) );
Even tho the field is not required, it gives me the error anyways.
Another question I have is about the use of multipleFiles = true. This doesn't work at all. Any idea why ?
Thank you so much !

The Repeater API does not currently support File Upload fields. Here's a full list of known limitations:
https://docs.gravityforms.com/repeater-fields/#limitations
If you need repeating file uploads, check out Gravity Forms Nested Forms:
https://gravitywiz.com/documentation/gravity-forms-nested-forms/

Related

Multiple Date Form Element in Drupal 9

I am trying to add a multiple date field (unlimited cardinality) in my custom module configuration form.
$form['holidayForm']['holidays'] = [
'#type' => 'date',
'#multiple' => TRUE,
'#title' => $this->t('Holidays'),
'#default_value' => $config->get('holidayForm.holidays'),
];
As you can see, I have added the #multiple property but I still get a single field
Is there a different property that I needed to add.

How to render custom form inside a custom block programmatically with drupal 8?

I need render a custom form in a custom block programmatically. This is my code inside a controller:
$form = \Drupal::formBuilder()->getForm('Drupal\wa_encuesta\Form\NewForm', $extra);
[enter image description here][1] $form=render($form);
$blockContent = BlockContent::create([
'info' => $title,
'type' => 'basic',
'body'=>[
'value' => $form,
'format' => 'full_html'
]
]);
$blockContent->save();
//$block = Block::create([
$block = \Drupal\block\Entity\Block::create([
'id' => 'about_us',
'plugin' => 'block_content:' . $blockContent->uuid(),
'region' => 'header',
'provider' => 'block_content',
'weight' => -100,
'theme' => \Drupal::config('system.theme')->get('default'),
'visibility' => array(),
'settings' => [
'label' => 'About us',
'label_display' => FALSE,
],
]);
$block->save();
The form render a custom block but this not working when submit.
I usually get this done by combination of hook_preprocess_block or hook_preprocess_node and twig file.
Example:
Say, you want to render this in a block:
Define hook_preprocess_block() in your theme file:
function THEME_preprocess_block(&$variables) {
$blockId = $variables['elements'][#id];
//check for your block id
$render_service = Drupal::service('renderer');
$form_html = $render_service->renderPlain(Drupal\wa_encuesta\Form\NewForm::class, $extra);
//set in variables
$variables['my_form_html'] = $form_html;
}
Now, identify your twig file name for your block, and just put:
{{ my_form_html }}
please see my answer to the same question here: How to create a form using block module in drupal 8?
Basically you just create a separate form and a block, render the form in the block and then place the block in the desired region.

How to add regex to attribute name in custom validations in Laravel?

In custom validation as shown below:
'custom' => array(
'attribute-name' => array(
'rule-name' => 'custom-message',
),
),
How is it possible to define regex along with the attribute-name-{regex} as well?!
Example:
'custom' => array(
'institute_regex:{/d{1}}' => array(
'required' => 'the field is required',
),
),
I think that might be what you were looking for ages ago, but anyway, here is what I did.
Had to find a way to define custom validation messages (in another language) for inputs dynamically generated in the frontend. The result is that I would get the following type of classes:
project_name-1, -2, -3 etc to keep it simple.
So what I did, and it worked just fine for me was adding the following lines to my validation.php file (whatever the language is):
'project_name-*' => [
'required' => 'Please name your project.',
],
And voilà, I hope it will help someone!

Custom Prestashop Admin Module

I am developing a module for prestashop (basically, it's a very custom import of data and the only thing I need is to have a form and process data). I have created controller class derived from the ModuleAdminController but the problem is where should I put the tpl file containing the look of my custom form?
I realize that I can put tpl file to the templates but I want to keep all files within my module folder, is it possible (probably somewhere like "/views/templates/admin")?
This is the most easy method to create a basic admin controller / action in Prestashop 1.6
Create basic configuration :
./config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>foo</name>
<displayName><![CDATA[Foo]]></displayName>
<version><![CDATA[2.1.3]]></version>
<description><![CDATA[Bar.]]></description>
<author><![CDATA[your-name]]></author>
<tab><![CDATA[administration]]></tab>
<is_configurable>0</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
./foo.php
if (!defined('_PS_VERSION_'))
exit;
class BarcodeEasyPrint extends Module
{
public function __construct()
{
$this->name = 'foo';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'your-name-here';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Foo');
$this->description = $this->l('Bar.');
if ((int)Tools::getValue('p'))
$this->page = (int)Tools::getValue('p');
}
}
You need to create the controller with base functions :
./controllers/admin/AdminFooController.php
class AdminFooController extends ModuleAdminController {
public function __construct() {
$this->bootstrap = true;
parent::__construct();
}
public function createTemplate($tpl_name) {
if (file_exists($this->getTemplatePath() . $tpl_name) && $this->viewAccess())
return $this->context->smarty->createTemplate($this- >getTemplatePath() . $tpl_name, $this->context->smarty);
return parent::createTemplate($tpl_name);
}
public function initContent(){
parent::initContent();
$tpl = $this->createTemplate('content.tpl')->fetch();
/* DO STUFF HERE */
$posts = array();
$this->context->smarty->assign('posts', $posts);
}
}
You can use boostrap directly in the template file :
./views/templates/admin/content.tpl
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
</div>
</div>
If it is an admin module only, then you will have no need to create any views. Because Prestashop provides a nice structure for admin section which is easy to use and we dont need to use any views or .tpl files. For admin section, normally three types of views or .tpl files are required, one for data display in grid, second for form and third for displaying a single record.
Prestashop already created .tpl files for them which you can find in "admin_folder/themes/default/templates". In our controllers for admin, for form and for data grid, we just create arrays and PS handles to view the form and data grid according to the arrays we created.
So if you need a custom form at admin, then create a public function renderForm and create the form array in it, like below:
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Video'),
'image' => '../img/admin/tab-genders.gif'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Video Title:'),
'name' => 'title',
'lang' => true,
'size' => 70,
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"�{}_$%:',
'required' => true
),
array(
'type' => 'textarea',
'label' => $this->l('Video Code'),
'name' => 'video_code',
'rows' => 5,
'cols' => 70,
'desc' => $this->l('Place the embed code for the video')
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
);
return parent::renderForm();
} /* End of render member */
For other fields, checkout other prestashop admin controllers and you will see that how easily we can create forms in PS using that simple definitions in the arrays and we dont need to create .tpl files.
For front end, we can use the new modules MVC structure, where our module folder have sub folders for controllers (controllers/front, controllers/admin) , views and models .
Hope this will help you.
Thank you
You need to use the helper form, here is the documentation for it, it is really easy to use ;) .
http://doc.prestashop.com/display/PS15/HelperForm
You also can find more information about how and where to use helper form, look for the function getContent() and displayForm().
http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module
unfortunately any document not exist to point directly to solve this question but hear i have some URLs really useful and you should combine theme and get your realize:
http://presthemes.com/prestashop-news/modules-classes-and-controller-override-by-julien-breux-4.html
http://doc.prestashop.com/display/PS15/Diving+into+PrestaShop+Core+development
http://doc.prestashop.com/display/PS15/New+Developers+Features+In+PrestaShop+1.5
http://blog.belvg.com/how-to-implement-a-controller.html
best regards
extending the answer from #altafhussain create a folder views/templates/admin in your module and place your customview.tpl
Than append the free text block as below.
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Legend')
),
'input' => array(
array(
'type' => 'free',
'label' => 'Whatever label text',
'desc' => $this->display(__FILE__,'views/templates/admin/customview.tpl'),
'name' => 'FREE_TEXT',
'required' => false
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
);
return parent::renderForm();
}

How to get the code for sharing the image of a facebook application to the users timeline?

Can I get the correct code of Facebook application, which allows to share or post the result image of the application to the users wall(Timeline).
Presently I am using the code below;-
$attachment = array(
'message' => 'this is my message',
'name' => 'This is my demo Facebook application! https://apps.facebook.com/whoisyourmillionare/',
'caption' => "Caption of the Post",
'description' => 'this is a description',
'picture' => 'http://www.nasa.gov/images/content/297522main_image_1244_946-710.jpg');
$result = $facebook->api('/me/feed/', 'post', $attachment);
and the out put is as per in the image 1
Actually I need to be as image 2