how to manage multiple form templates in fuelphp - php

Hello I just migrated from CI to Fuel.... I am using Fieldset class to auto generate form in the view.... The problem i am facing is I have multiple types of form templates i.e some of my models use twitter bootstrap horizontal inline form where as few models use custom templates... I am able to set single type of form template in form.php which i copy from fuel/core/config/form.php to fuel/app/config/form.php
Here is the sample return array for form template
return array(
// regular form definitions
'prep_value' => true,
'auto_id' => true,
'auto_id_prefix' => 'form_',
'form_method' => 'post',
'form_template' => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n",
'fieldset_template' => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n",
'field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n",
'multi_field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n",
'error_template' => '<span>{error_msg}</span>',
'group_label' => '<span>{label}</span>',
'required_mark' => '*',
'inline_errors' => false,
'error_class' => null,
'label_class' => null,
// tabular form definitions
'tabular_form_template' => "<table>{fields}</table>\n",
'tabular_field_template' => "{field}",
'tabular_row_template' => "<tr>{fields}</tr>\n",
'tabular_row_field_template' => "\t\t\t<td>{label}{required} {field} {error_msg}</td>\n",
'tabular_delete_label' => "Delete?",
);
I want multiple form templates like this so that i will be able to auto generate the form where it is needed using $fieldset->form()->build() function...
Is there any way to do this??

yes. try this:
forge($name = 'default', $config = array());
$article_form = Fieldset::forge('article',array(
// regular form definitions
'prep_value' => true,
'auto_id' => true,
'auto_id_prefix' => 'form_',
'form_method' => 'post',
'form_template' => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n",
'fieldset_template' => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n",
'field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n",
'multi_field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n",
'error_template' => '<span>{error_msg}</span>',
'group_label' => '<span>{label}</span>',
'required_mark' => '*',
'inline_errors' => false,
'error_class' => null,
'label_class' => null,
// tabular form definitions
'tabular_form_template' => "<table>{fields}</table>\n",
'tabular_field_template' => "{field}",
'tabular_row_template' => "<tr>{fields}</tr>\n",
'tabular_row_field_template' => "\t\t\t<td>{label}{required} {field} {error_msg}</td>\n",
'tabular_delete_label' => "Delete?",
));

Related

Unable to retrieve data from parent form in InlineCreate operation in backpack for laravel

I implement the InlineCreate Operation in Backpack for Laravel and works fine, but my field depend of other field and I can't to get the parent field information in the modal or in the setup operation.
Field Definition
$this->crud->addField([
'name' => 'cliente_contacto',
'type' => "relationship",
'ajax' => true,
//'inline_create' => true,
'inline_create' => [ // specify the entity in singular
'entity' => 'cliente_contacto', // the entity in singular
// OPTIONALS
'force_select' => true, // should the inline-created entry be immediately selected?
'modal_class' => 'modal-dialog modal-lg', // use modal-sm, modal-lg to change width
'modal_route' => route('cliente-contacto-inline-create'), // InlineCreate::getInlineCreateModal()
'create_route' => route('cliente-contacto-inline-create-save'), // InlineCreate::storeInlineCreate()
'include_main_form_fields' => ['proyecto'] // pass certain fields from the main form to the modal
],
// 'data_source' => backpack_url('presupuesto/fetch/cliente-contacto'),
// 'placeholder' => 'Seleccione un elemento',
'minimum_input_length' => 0,
'dependencies' => ['cliente'], // when a dependency changes, this select2 is reset to null
//'method' => 'POST', // optional - HTTP method to use for the AJAX call (GET, POST)
//'include_all_form_fields' => true, //sends the other form fields along with the request so it can be filtered.
'tab' => 'Datos Principales',
'wrapper' => [
'class' => 'col-md-3'
]
]);
ClienteContactoCrudController
protected function setupInlineCreateOperation()
{
$parent_loaded_fields = request()->get('parent_loaded_fields');
}
But I can't get that fields.
The documentation:
https://backpackforlaravel.com/docs/5.x/crud-operation-inline-create#how-to-use-1
'include_main_form_fields' => ['field1', 'field2'], // pass certain fields from the main form to the modal
Don't said how get that values.
I found this: https://github.com/Laravel-Backpack/CRUD/issues/2925#issuecomment-644060749
I can get:
'entity' => request()->get('entity'),
'modalClass' => request()->get('modal_class'),
But
'parentLoadedFields' => request()->get('parent_loaded_fields')
Don't work
How can I get de parent field values?
you should get them with request('main_form_fields').
I've just submitted a PR to the docs to reference that: https://github.com/Laravel-Backpack/docs/pull/341
Cheers

mongoDB, PHP update specific value not all the values

I am having a problem in updating values i get from web service ..
$collection = $modb->$table;
$collection->update(array("id" => (int)$row['id']),
array('$set' => array(
"user_id" => (int)$post_data_array['user_id'],
"story" => (int)$post_data_array['story'],
"surprize_sub1" => (int)$post_data_array['surprize_sub1'],
"surprize_sub2" => (int)$post_data_array['surprize_sub2'],
"surprize_sub3" => (int)$post_data_array['surprize_sub3'],
"exr_solve" => (int)$post_data_array['exr_solve'],
"exr_assessmnt" => (int)$post_data_array['exr_assessmnt'],
"exr_refresh" => (int)$post_data_array['exr_refresh'],
"sound_control" => (int)$post_data_array['sound_control'],
"clock_control" => (int)$post_data_array['clock_control'],
"switch_user" => (int)$post_data_array['switch_user'],
"exr_print" => (int)$post_data_array['exr_print'],
"write_on_wall" => (int)$post_data_array['write_on_wall'],
"switch_letter" => (int)$post_data_array['switch_letter'],
"view_controls" => (int)$post_data_array['view_controls'],
)));
I get these values from end users.. i want the specific field sent to be updated without loosing all the rest of data ..
in this code only sent data is set while removing the rest .. i want to change only sent ones by keeping the rest as they are, please advice
you need to use updateOne instead of update .
updateOne
Use the MongoDB\Collection::updateOne() method to update a single document matching a filter.
$collection = $modb->$table;
$collection->updateOne(array("id" => (int)$row['id']),
array('$set' => array(
// .... array elements
)));

Filter list that does not have an invalid email and opt-out email using SugarCRM 7 API

I want to filter list that does not have an invalid email and opt-out email in Leads and Contact module using SugarCRM 7 API.
I have added below email filter in arguments but does not work. How to email filter via SugarCRM 7.x rest API.
$filter_arguments = array(
"filter" => array(
array(
"assigned_user_id" => 1,
),
array(
"email1" => array(
array(
'opt_out' => array(
'$equals' => ''
)
)
)
),
),
);
$url = $base_url . "/Contacts/filter";
Thanks.
This much code will not help you please check this :
Reference Link 1
Reference Link 2
The following example will demonstrate how to add a predefined filter on the Accounts module to return all records with an account type of "Customer" and industry of "Other".
To create a predefined filter, create a display label extension in ./custom/Extension/modules/<module>/Ext/Language/. For this example, we will create:
./custom/Extension/modules/Accounts/Ext/Language/en_us.filterAccountByTypeAndIndustry.php
<?php
$mod_strings['LBL_FILTER_ACCOUNT_BY_TYPE_AND_INDUSTRY'] = 'Customer/Other Accounts';
Next, create a custom filter extension in ./custom/Extension/modules/<module>/Ext/clients/base/filters/basic/.
For this example, we will create:
./custom/Extension/modules/Accounts/Ext/clients/base/filters/basic/filterAccountByTypeAndIndustry.php
<?php
$viewdefs['Accounts']['base']['filter']['basic']['filters'][] = array(
'id' => 'filterAccountByTypeAndIndustry',
'name' => 'LBL_FILTER_ACCOUNT_BY_TYPE_AND_INDUSTRY',
'filter_definition' => array(
array(
'account_type' => array(
'$in' => array(
'Customer',
),
),
),
array(
'industry' => array(
'$in' => array(
'Other',
),
),
),
),
'editable' => false,
'is_template' => false,
);
You should notice that the editable and is_template options have been set to "false". If editable is not set to "false", the filter will not be displayed in the list view filter's list.
Finally, navigate to Admin > Repair and click "Quick Repair and Rebuild" to rebuild the extensions and make the predefined filter available for users.
Adding Initial Filters to Lookup Searches
To add initial filters to record lookups and type-ahead searches, define a filter template. This will allow you to filter results for users when looking up a parent related record. The following example will demonstrate how to add an initial filter for the Account lookup on the Contacts module. This initial filter will limit records to having an account type of "Customer" and a dynamically assigned user value determined by the contact's assigned user.
To add an initial filter to the Contacts record view, create a display label for the filter in ./custom/Extension/modules/<module>/Ext/Language/. For this example , we will create:
./custom/Extension/modules/Accounts/Ext/Language/en_us.filterAccountTemplate.php
<?php
$mod_strings['LBL_FILTER_ACCOUNT_TEMPLATE'] = 'Customer Accounts By A Dynamic User';
Next, create a custom template filter extension in ./custom/Extension/modules/<module>/Ext/clients/base/filters/basic/.
For this example, create:
./custom/Extension/modules/Accounts/Ext/clients/base/filters/basic/filterAccountTemplate.php
<?php
$viewdefs['Accounts']['base']['filter']['basic']['filters'][] = array(
'id' => 'filterAccountTemplate',
'name' => 'LBL_FILTER_ACCOUNT_TEMPLATE',
'filter_definition' => array(
array(
'account_type' => array(
'$in' => array(),
),
),
array(
'assigned_user_id' => ''
)
),
'editable' => true,
'is_template' => true,
);
As you can see, the filter_definition contains arrays for account_type and assigned_user_id. These filter definitions will receive their values from the contact record view's metadata. You should also note that this filter has is_template and editable set to "true". This is required for initial filters.
Once the filter template is in place, modify the contact record view's metadata. To accomplish this, edit ./custom/modules/Contacts/clients/base/views/record/record.php to adjust the account_name field. If this file does not exist in your local Sugar installation, navigate to Admin > Studio > Contacts > Layouts > Record View and click "Save & Deploy" to generate it. In this file, identify the panel_body array as shown below:
1 =>
array (
'name' => 'panel_body',
'label' => 'LBL_RECORD_BODY',
'columns' => 2,
'labelsOnTop' => true,
'placeholders' => true,
'newTab' => false,
'panelDefault' => 'expanded',
'fields' =>
array (
0 => 'title',
1 => 'phone_mobile',
2 => 'department',
3 => 'do_not_call',
4 => 'account_name',
5 => 'email',
),
),
Next, modify the account_name field to contain the initial filter parameters.
1 =>
array (
'name' => 'panel_body',
'label' => 'LBL_RECORD_BODY',
'columns' => 2,
'labelsOnTop' => true,
'placeholders' => true,
'newTab' => false,
'panelDefault' => 'expanded',
'fields' =>
array (
0 => 'title',
1 => 'phone_mobile',
2 => 'department',
3 => 'do_not_call',
4 => array (
//field name
'name' => 'account_name',
//the name of the filter template
'initial_filter' => 'filterAccountTemplate',
//the display label for users
'initial_filter_label' => 'LBL_FILTER_ACCOUNT_TEMPLATE',
//the hardcoded filters to pass to the templates filter definition
'filter_populate' => array(
'account_type' => array('Customer')
),
//the dynamic filters to pass to the templates filter definition
//please note the index of the array will be for the field the data is being pulled from
'filter_relate' => array(
//'field_to_pull_data_from' => 'field_to_populate_data_to'
'assigned_user_id' => 'assigned_user_id',
)
),
5 => 'email',
),
),
Finally, navigate to Admin > Repair and click "Quick Repair and Rebuild". This will rebuild the extensions and make the initial filter available for users when selecting a parent account for a contact.
Adding Initial Filters to Drawers from a Controller
When creating your own views, you may need to filter a drawer called from within your custom controller. Using an initial filter, as described in the Adding Initial Filters to Lookup Searches section, we can filter a drawer with predefined values by creating a filter object and populating the config.filter_populate property as shown below:
//create filter
var filterOptions = new app.utils.FilterOptions()
.config({
'initial_filter': 'filterAccountTemplate',
'initial_filter_label': 'LBL_FILTER_ACCOUNT_TEMPLATE',
'filter_populate': {
'account_type': ['Customer'],
'assigned_user_id': 'seed_sally_id'
}
})
.format();
//open drawer
app.drawer.open({
layout: 'selection-list',
context: {
module: 'Accounts',
filterOptions: filterOptions,
parent: this.context
}
});
To create a filtered drawer with dynamic values, create a filter object and populate the config.filter_relate property using the populateRelate method as shown below:
//record to filter related fields by
var contact = app.data.createBean('Contacts', {
'first_name': 'John',
'last_name': 'Smith',
'assigned_user_id': 'seed_sally_id'
});
//create filter
var filterOptions = new app.utils.FilterOptions()
.config({
'initial_filter': 'filterAccountTemplate',
'initial_filter_label': 'LBL_FILTER_ACCOUNT_TEMPLATE',
'filter_populate': {
'account_type': ['Customer'],
},
'filter_relate': {
'assigned_user_id': 'assigned_user_id'
}
})
.populateRelate(contact)
.format();
//open drawer
app.drawer.open({
layout: 'selection-list',
context: {
module: 'Accounts',
filterOptions: filterOptions,
parent: this.context
}
});

set data to entity field with query_builder and multiple true

I have the following field
->add('specialProduct' , 'entity', array(
'class' => 'BSSmartDistributionBundle:Product',
'expanded' => true,
'multiple' => true,
'required' => true,
'label' => false,
'mapped' => false,
'query_builder' => function(ProductRepository $er) {
return $er->createQueryBuilder('p')
->where('p.active = :active')
->andWhere('p.type = :type')
->setParameter('type', 1)
->setParameter('active', 1);
},
'data' => $this->specialProduct # not working
))
I get the data and store it in session
$specialProduct = $form->get('specialProduct')->getData();
$request->getSession()->set('specialProduct', $specialProduct);
data :
Doctrine\Common\Collections\ArrayCollection Object
(
[elements:Doctrine\Common\Collections\ArrayCollection:private] => Array
(
[0] => BS\SmartDistributionBundle\Entity\Product Object
(
[id:BS\SmartDistributionBundle\Entity\Product:private] => 6
[type:BS\SmartDistributionBundle\Entity\Product:private] => 1
[name:BS\SmartDistributionBundle\Entity\Product:private] => Starter Pack
[duration:BS\SmartDistributionBundle\Entity\Product:private] => 1
[description:BS\SmartDistributionBundle\Entity\Product:private] => Tout de suite
[full_description:BS\SmartDistributionBundle\Entity\Product:private] => blabla
[price:BS\SmartDistributionBundle\Entity\Product:private] => 39
[picture:BS\SmartDistributionBundle\Entity\Product:private] => /tmp/php6h3rXK
[active:BS\SmartDistributionBundle\Entity\Product:private] => 1
)
[1] => BS\SmartDistributionBundle\Entity\Product Object
(
[id:BS\SmartDistributionBundle\Entity\Product:private] => 15
[type:BS\SmartDistributionBundle\Entity\Product:private] => 1
[name:BS\SmartDistributionBundle\Entity\Product:private] => asdsd
[duration:BS\SmartDistributionBundle\Entity\Product:private] => 2
[description:BS\SmartDistributionBundle\Entity\Product:private] => asdasd
[full_description:BS\SmartDistributionBundle\Entity\Product:private] => adsd
[price:BS\SmartDistributionBundle\Entity\Product:private] => 12
[picture:BS\SmartDistributionBundle\Entity\Product:private] => uploads/product/d978b90215d06fbf569203e7cf2d5aef.png
[active:BS\SmartDistributionBundle\Entity\Product:private] => 1
)
)
)
now I'd like to check the corresponding checkboxes !?
Same field with multiple false I can set the value with
'data' => $this->value
I tried
'data' => $this->specialProduct # not working (contains $specialProduct above)
How can I set those values ?
Do I need to pass an array ?
Thanks !
Setting default values for a form is always done on an instance of FormInterface using setData and not as data in options array for each form field. The docs says:
The default values for form fields are taken directly from the underlying data structure (e.g. an entity or an array). The data option overrides this default value.
If you used data option than the form will always have preselected what's in data and not from the entity.
So if I understand your code correctly it'd be:
$form->setData([
specialProduct => $request->getSession()->get('specialProduct')
]);
Because the stored data in session is a collection of Products.
I ended doing it this way :
I was storing and passing to the form an arrayCollection
controller :
$specialProduct = $form->get('specialProduct')->getData();
$request->getSession()->set('specialProduct', $specialProduct);
form :
$this->specialProduct = $options['specialProduct'];
'data' => $this->specialProduct
instead I use an array with only the ids
foreach ($specialProduct as $product) {
$specialProductIds[] = $product->getId();
}
$request->getSession()->set('specialProductIds', $specialProductIds);
pass it to the form with entity manager
$this->specialProductIds = $options['specialProductIds'];
$this->em = $options['em'];
in the form
public function availablespcialProduct($ids) {
if ($this->em) {
return $this->em
->getRepository('BS\SmartDistributionBundle\Entity\Product')
->findById(
$ids
);
}
}
and finally
'data' => $this->availablespcialProduct($this->specialProductIds)
Still waiting for a cleaner solution !
Thanks !

create a .php file through the launch of a .bat

I need to launch a .bat file that creates a php file, containing this text:
<?php
$_mail_mailSpooler = array (
'classname' => 'mail_mailSpooler',
'from' => 'test#test.com',
'array_indirizzi_mail' =>
array (
0 => ‘lol#hotmail.com’,
'testo_mail' => ‘prova’,
'filename_html' => NULL,
'oggetto_mail' => ‘prova’,
'elenco_allegati' => '',
'forza_mail_txt' => 0,
'asl_logger' => '',
'log_identifier' => NULL,
'log_in_web' => 0,
'log_str' => '',
'nome_file_dump' => '../mailSpooler/mail_incoming/maildda2.php',
);
I have tried echo " (test)" >gnagna.php
but it doen't work.
any suggestion please?
thanks
use type instead of echo - echo's only supposed to give user feedback, file reading and writing is properly done by type. Have a look at http://www.robvanderwoude.com/allhelpw2ksp4_en.php#TYPE for more
sorry, but i'm not already able to launch my php with right code.
i've tried type <?php
$_mail_mailSpooler = array (
'classname' => 'mail_mailSpooler',
'from' => 'test#test.com',
'array_indirizzi_mail' =>
array (
0 => ‘lol#hotmail.com’,
'testo_mail' => ‘prova’,
'filename_html' => NULL,
'oggetto_mail' => ‘prova’,
'elenco_allegati' => '',
'forza_mail_txt' => 0,
'asl_logger' => '',
'log_identifier' => NULL,
'log_in_web' => 0,
'log_str' => '',
'nome_file_dump' => '../mailSpooler/mail_incoming/maildda2.php',
); C:\>test.php
but it doesn't work.
moreover your link says that this command displays the content of an existing file and i need to create a new one!

Categories