Adding a value to a textbox generated on Symfony 2 - symfony

Having this:
echo $view['form'] -> row($form["codelist"], array(
//widget
"widgetArgs" => array(
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist"
),
"tooltip"=>"gift.tooltip.codelist",
"translation_domain" =>"brand"
),
"labelArgs" => array(
"label_attr" => array(
'class' => 'control-label',
)) ,"rowType"=>2
)
);
How do you add an initial value to that textbox?

If you want to add an actual value to the field, you can use the value attribute:
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist",
'value' => "Your initial value"
)
But if you are using HTML5 and just want to give a hint to your users, you'd better use a placeholder:
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist",
'placeholder' => "Your initial value"
)
http://www.w3.org/html/wg/drafts/html/master/forms.html#the-placeholder-attribute

Related

Wordpress - Trying to display date from custom form two different ways

I am trying to create an events page in Wordpress. I am using the Advanced Custom Fields plugin to generate my forms. I would like to style the month and year differently from the day in the listing section. However, I don't want to make the user have to input the same date twice in the back-end just for this. Is there a way to display the content from the one form in two different calibrations on the front-end? For example, can I display it once as month and year then once again as just the day? Is there any other workaround? Any advice would be appreciated.
Here is my custom form code:
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5fec83c0a2f7b',
'title' => 'Event Particulars',
'fields' => array(
array(
'key' => 'field_5fec83ca0dc8b',
'label' => 'Date of event',
'name' => 'date_of_event',
'type' => 'date_picker',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5fec84a00dc8c',
'operator' => '!=empty',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'display_format' => 'Y F j',
'return_format' => 'Y F j',
'first_day' => 1,
),
array(
'key' => 'field_5fec84a00dc8c',
'label' => '',
'name' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'page_type',
'operator' => '==',
'value' => 'front_page',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
You can load the value of the date field, create a date object and then format that date object as you prefer:
// Load field value.
$date_string = get_field('date_of_event');
// Create DateTime object from value.
// Here you must use the format that you specified as the "return format" of the date field in ACF.
$date = DateTime::createFromFormat('Y F j', $date_string);
// Now you can use the date object to print the date in different formats:
echo $date->format('M Y');
echo $date->format('j M Y');
Have a look at the "Modifiy value" section of the docs:
https://www.advancedcustomfields.com/resources/date-picker/

Input type number in HelperForm PrestaShop

I am unable to set input type number in HelperForm PrestaShop.
Only text and password types are working. When set to number type, the input box disappears.
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Settings'),
),
'input' => array(
array(
'type' => 'number',
'label' => $this->l('Number Input'),
'name' => 'NumberInput',
'required' => true
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
)
);
You can set the type as follows:
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Settings'),
),
'input' => array(
array(
'type' => 'html',
'label' => $this->l('Number Input'),
'name' => 'NumberInput',
'required' => true,
'html_content' => '<input type="number" name="NumberInput">'
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
)
);
You can use for examplemin="1" max="5"in the input.
According to the form.tpl in admin theme, this should work.
There is no number type in PrestaShop helper forms, that is the only reason the input box disappears when you put type as number.
What you can do to achieve this is to create a simple input field and add help text or tooltip to indicate that this field only accepts numeric values. Following code can be used to add help text or tooltip to the HelperForm.
array(
'type' => 'text',
'label' => 'Custom Label',
'required' => true,
'hint' => 'Custom Tool Tip',
'desc' => 'Custom Help Text'
)
In the validation part, you can use the put the validation for numbers only and return an error if the value entered is not as expected.

Error: One or more parameter values were invalid--DynamoDb

I am trying to update a table in DynamoDb with the following code..
$response = $client->updateItem(array(
"TableName" => "PlayerInfo",
"Key" => array(
"PlayerId" => array('N' => '201503261435580358849074082'),
),
"AttributeUpdates" => array(
'PlayerPrice' => array(
'N' => '5'
),
),
"ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW
));
print_r($response);
However, an error interrupts its execution. It says:
One or more parameter values were invalid: Only DELETE action is allowed
when no attribute value is specified.
Could anybody help me with this issue?
Looks like the for format of the request was missing the 'Action' and 'Value' parameters. E.g. the following is working for me:
$response = $client->updateItem(array(
"TableName" => "PlayerInfo",
"Key" => array(
"PlayerId" => array('N' => '201503261435580358849074082'),
),
"ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW,
"AttributeUpdates" => array(
'PlayerPrice' => array(
'Action' => \Aws\DynamoDb\Enum\AttributeAction::PUT,
'Value' => array('N' => '5'),
)
)
));
print_r($response);
You can also use an UpdateExpression to achieve the same effect (UpdateExpressions also provide greater flexibility than AttributeUpdates so they are generally recommended):
$response = $client->updateItem(array(
"TableName" => "PlayerInfo",
"Key" => array(
"PlayerId" => array('N' => '201503261435580358849074082'),
),
"ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW,
"UpdateExpression" => "SET #pp = :val",
"ExpressionAttributeNames" => array(
"#pp" => "PlayerPrice",
),
"ExpressionAttributeValues" => array(
':val' => array('N' => '5')
)
));
print_r($response);

make CMB text_datetime_timestamp field repeatable

I'm using CMB to creat custom fields for wordpress custom post
https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress
I'm using text_datetime_timestamp to set date and time and I need to make this field repeatable which is not
as I go through the documentation we can make new fields but I can't figure out how it make "text_datetime_timestamp" field repeatable
any body can show me the way to accomplish that ?
thank you
I did not find a solution to make the field repeatable so I put the field inside group and made it repeatable
array(
'id' => $prefix . 'repeat_date_group',
'type' => 'group',
'description' => '',
'options' => array(
'group_title' => __( 'Date/Time {#}', 'cmb' ),
'add_button' => __( 'Add Another Date/Time', 'cmb' ),
'remove_button' => __( 'Remove Date/Time', 'cmb' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Date/Time',
'desc' => '',
'id' => $prefix . 'course_date',
'type' => 'text_datetime_timestamp'
),
),
),
I hope this answer will help somebody
Well here is my code, you may try this
$cmb= new_cmb2_box( array(
'id' => $prefix.'testing',
'title' => _('Testing'),
'object_types' => array('post'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
));
$cmb->add_field( array(
'name' => 'Test Date/Time Picker Combo (UNIX timestamp)',
'id' => 'wiki_test_datetime_timestamp',
'type' => 'text_datetime_timestamp',
'repeatable' => true,
) );

View fields from the same database column

So, I have serialized data within the uc_orders table. This data has several parameters of interest each of which I want to create a unique field from.
Each one of these $data values work on their own. Obviously I am rewriting the value on the second declaration. How can I reference the same data location twice so that both of the fields can be used and I can explode all of my serialized data into separate fields?
function uc_order_views_data() {
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order by.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
}
I finally found the answer.
$data['uc_orders']['data2'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'real field' => 'data',
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
The solution is to add 'real field' => 'field name', and change the $data id.

Resources