Osclass forums
Support forums => General help => 3.6.x => Topic started by: serjuc11111 on November 08, 2016, 04:39:10 pm
-
I have a meta input like :
<input id="meta_new-custom-field" name="meta[42]" value="" type="text">
how to set params for this input:?
Params::setParam("meta[42]","0123456789");//not working
$_POST[meta[42]] = '0123456789';//not workig too
meta field: pk_i_id - 42 s_name -> Phone* ,
thx!
-
No help for this one?What im doing wrong....??
-
If you will need to solve this ,use
where $br=fk_i_field_id
Params::setParam('meta',array($br=>'0123456789'));
-
If you will need to solve this ,use
where $br=fk_i_field_id
Params::setParam('meta',array($br=>'0123456789'));
how did you solve this? please share with us!
i want to get and set the value of a custom-field in item-post.php
$get_value = Params::getParam('meta[42]'); //Getting the value = Not working!
Params::setParam('meta[42]', '999'); //Setting the value = Not working!
-
If you will need to solve this ,use
where $br=fk_i_field_id
Params::setParam('meta',array($br=>'0123456789'));
how did you solve this? please share with us!
i want to get and set the value of a custom-field in item-post.php
$get_value = Params::getParam('meta[42]'); //Getting the value = Not working!
Params::setParam('meta[42]', '999'); //Setting the value = Not working!
meta is an ARRAY. Which means getParam('meta[field_id]') won't work, you need to get meta variable and access it's key - getParam('meta')['field_id']. Probably same for setParam, never used that function so...
Regards.
-
If you will need to solve this ,use
where $br=fk_i_field_id
Params::setParam('meta',array($br=>'0123456789'));
how did you solve this? please share with us!
i want to get and set the value of a custom-field in item-post.php
$get_value = Params::getParam('meta[42]'); //Getting the value = Not working!
Params::setParam('meta[42]', '999'); //Setting the value = Not working!
meta is an ARRAY. Which means getParam('meta[field_id]') won't work, you need to get meta variable and access it's key - getParam('meta')['field_id']. Probably same for setParam, never used that function so...
Regards.
what is the format for setting?
Params::setParam('meta[42]', '$cf_value'); //Not working!
Params::setParam(('meta')[42], '$cf_value'); //Parse error: syntax error, unexpected '[' in ...
-
Try this:
$old_meta = Params::getParam('meta');
$new_meta = $old_meta;
$new_meta[42] = 'Value for field 42';
Params::setParam('meta', $new_meta);
Regards.
-
Try this:
$old_meta = Params::getParam('meta');
$new_meta = $old_meta;
$new_meta[42] = 'Value for field 42';
Params::setParam('meta', $new_meta);
Regards.
i put this code in header, but when i load item-post.php, custom-field-42 didn't get "Value for field 42" value on page-load! and it was empty!
-
Where exactly do you want to get and modify this meta field?
Regards.
-
Where exactly do you want to get and modify this meta field?
Regards.
in item-post.php i want to get and replace! (posted_item hook)
not with sql, i just want to get the value of CF and replace it!
-
Try doing that in pre_item_post. Param is already saved when posted_item runs.
Regards.
-
Try doing that in pre_item_post. Param is already saved when posted_item runs.
Regards.
Not working!
I even put that code directly in header.php and didn't work!
-
@patrickFromCroatia
Did you find a way to do this?
-
So you want to change the value of the meta param before it's saved in the database? Or can you update it in the database later?
Regards.
-
So you want to change the value of the meta param before it's saved in the database? Or can you update it in the database later?
Regards.
i know how to update the database to change it with posted_item hook! i don't wanna use database to do this!
i want to replace the value of the meta param before it's saved in the database!
-
So you can't use posted_item as it runs when all data is already saved in the database. I will check if we can modify meta value saved in session with pre_item_post.
Regards.
-
Thank you!
-
According to my quick research, this should work...
<?php
function wm_item_pre_post_session_edit() {
$key = 10; // Your meta field ID.
$meta = Params::getParam('meta'); // Get all meta fields.
if(@$meta[$key] == null) return; // Stop the function if your specific meta field doesn't exist. @ is added to stop warnings if $meta is not an array.
$old_value = $meta[$key]; // Get value from your meta field.
$new_value = 'New value'; // Put new value for your meta field.
Session::newInstance()->_setForm('meta_'.$key, $new_value); // Save new value.
Session::newInstance()->_keepForm('meta_'.$key);
}
osc_add_hook('pre_item_post', 'wm_item_pre_post_session_edit');
Regards.
-
According to my quick research, this should work...
<?php
function wm_item_pre_post_session_edit() {
$key = 10; // Your meta field ID.
$meta = Params::getParam('meta'); // Get all meta fields.
if(@$meta[$key] == null) return; // Stop the function if your specific meta field doesn't exist. @ is added to stop warnings if $meta is not an array.
$old_value = $meta[$key]; // Get value from your meta field.
$new_value = 'New value'; // Put new value for your meta field.
Session::newInstance()->_setForm('meta_'.$key, $new_value); // Save new value.
Session::newInstance()->_keepForm('meta_'.$key);
}
osc_add_hook('pre_item_post', 'wm_item_pre_post_session_edit');
Regards.
thank you very much for the code but i exactly paste this code in my functions.php and changed the 10 to my custom-filed id (oc_t_meta_fields -> pk_i_id), but after publishing the item, its value did NOT change to 'New value'
-
I did more research and I think there is no other way but to update the database or to change core files. I used both Session and Param classes to try to modify meta, but I noticed that meta fields are already saved in a variable when pre_item_post runs.
ItemActions.php:149
$meta = Params::getParam("meta"); // META IS SET HERE.
foreach($_meta as $_m) {
$meta[$_m['pk_i_id']] = (isset($meta[$_m['pk_i_id']]))?$meta[$_m['pk_i_id']]:'';
}
if($meta!='' && count($meta)>0) {
$mField = Field::newInstance();
foreach($meta as $k => $v) {
if($v=='') {
$field = $mField->findByPrimaryKey($k);
if($field['b_required']==1) {
$flash_error .= sprintf(_m("%s field is required."), $field['s_name']) . PHP_EOL;
}
}
}
}
// hook pre add or edit
// DEPRECATED: pre_item_post will be removed in 3.4
osc_run_hook('pre_item_post'); // CHANGING PARAM OR SESSION HERE DOES NOT AFFECT ANYTHING.
Regards.
-
I did more research and I think there is no other way but to update the database or to change core files. I used both Session and Param classes to try to modify meta, but I noticed that meta fields are already saved in a variable when pre_item_post runs.
ItemActions.php:149
$meta = Params::getParam("meta"); // META IS SET HERE.
foreach($_meta as $_m) {
$meta[$_m['pk_i_id']] = (isset($meta[$_m['pk_i_id']]))?$meta[$_m['pk_i_id']]:'';
}
if($meta!='' && count($meta)>0) {
$mField = Field::newInstance();
foreach($meta as $k => $v) {
if($v=='') {
$field = $mField->findByPrimaryKey($k);
if($field['b_required']==1) {
$flash_error .= sprintf(_m("%s field is required."), $field['s_name']) . PHP_EOL;
}
}
}
}
// hook pre add or edit
// DEPRECATED: pre_item_post will be removed in 3.4
osc_run_hook('pre_item_post'); // CHANGING PARAM OR SESSION HERE DOES NOT AFFECT ANYTHING.
Regards.
@patrickFromCroatia Thank you so much!