Skip to main content
removed "Drupal" and tags from the title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Using Which parameters should I pass to form_set_value() in Drupal 7?

I am trying to update a value during the validate phase of a node-form, i.e. if form: When the custom validation error is fired, justI empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea whatuse the different values meanfollowing code.

the function is: form_set_value($element, $value, &$form_state)

function eventcheck_node_validate($node, $form, &$form_state) {
  if ($node->type == 'article') {
    if ((array_key_exists('endpoints',$node->field_event_choose['und'][0])) && (($node->field_event_title['und'][0]['value']<>'') || (isset($node->field_event['und'][0]['value'])))) {
      $form_set_value(???);
      $form_set_error('event_checker_group',t('Error message'));
    }
  }
}

now iI understand that the last valueparameter for form_set_value() is simply the $form_state, that I am having throughsame $form_state the validate functionvalidation handler gets. but what about $elementWhat are the $element and $valuethe $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value']$form['field_name']['und'][0]['value']['#value'] and only there.

but when When I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo'try form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state),$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:get this error.

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

[EDIT2]I also tried the following code.

    //calls when node is being created
    function eventcheck_node_validate($node,$form,&$form_state) {
      //checks if the node type is applicable
      if($node -> type=='article') {
        //checks if field 'field_event_choose' AND either 'field_event_title' 
        //or 'field_event' is supplied, if so, fire form_set_value() and form_set_error()
        if ((array_key_exists('endpoints',$node -> field_event_choose['und'][0])) && 
        (($node -> field_event_title['und'][0]['value']<>'') || (isset($node -> 
        field_event['und'][0]['value'])))) {
        
          //fire away
          $form_set_value(???);
          $form_set_error('event_checker_group',t('sorry blabla'));
        
        }
      }
    }
$newvalue = $form['field_name']['und'][0]['value'];
$newvalue['#value']='foo';
form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

I hope that helpsget this error.

Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Using form_set_value() in Drupal 7

I am trying to update a value during the validate phase of a node-form, i.e. if the custom validation error is fired, just empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea what the different values mean.

the function is: form_set_value($element, $value, &$form_state)

now i understand that the last value is simply the $form_state, that I am having through the validate function. but what about $element and $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there.

but when I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

[EDIT2]

    //calls when node is being created
    function eventcheck_node_validate($node,$form,&$form_state) {
      //checks if the node type is applicable
      if($node -> type=='article') {
        //checks if field 'field_event_choose' AND either 'field_event_title' 
        //or 'field_event' is supplied, if so, fire form_set_value() and form_set_error()
        if ((array_key_exists('endpoints',$node -> field_event_choose['und'][0])) && 
        (($node -> field_event_title['und'][0]['value']<>'') || (isset($node -> 
        field_event['und'][0]['value'])))) {
        
          //fire away
          $form_set_value(???);
          $form_set_error('event_checker_group',t('sorry blabla'));
        
        }
      }
    }

I hope that helps.

Which parameters should I pass to form_set_value()?

I am trying to update a value during the validate phase of a node form: When the custom validation error is fired, I empty one of the fields.

I am trying to use the following code.

function eventcheck_node_validate($node, $form, &$form_state) {
  if ($node->type == 'article') {
    if ((array_key_exists('endpoints',$node->field_event_choose['und'][0])) && (($node->field_event_title['und'][0]['value']<>'') || (isset($node->field_event['und'][0]['value'])))) {
      $form_set_value(???);
      $form_set_error('event_checker_group',t('Error message'));
    }
  }
}

I understand that the last parameter for form_set_value() is the same $form_state the validation handler gets. What are the $element and the $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there. When I try form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state), I get this error.

Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

I also tried the following code.

$newvalue = $form['field_name']['und'][0]['value'];
$newvalue['#value']='foo';
form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

I get this error.

Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Tweeted twitter.com/StackDrupal/status/785099614584274944
Removed depreciated API tag, re-tagged with 'form-api', added link to documentation for form_set_value(), modified title
Source Link

drupal7: using Using form_set_value() in Drupal 7

I am trying to update a value during the validate phase of a node-form, i.e. if the custom validation error is fired, just empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea what the different values mean.

the function is: form_set_valueform_set_value($element, $value, &$form_state)

now i understand that the last value is simply the $form_state, that I am having through the validate function. but what about $element and $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there.

but when I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

[EDIT2]

    //calls when node is being created
    function eventcheck_node_validate($node,$form,&$form_state) {
      //checks if the node type is applicable
      if($node -> type=='article') {
        //checks if field 'field_event_choose' AND either 'field_event_title' 
        //or 'field_event' is supplied, if so, fire form_set_value() and form_set_error()
        if ((array_key_exists('endpoints',$node -> field_event_choose['und'][0])) && 
        (($node -> field_event_title['und'][0]['value']<>'') || (isset($node -> 
        field_event['und'][0]['value'])))) {
        
          //fire away
          $form_set_value(???);
          $form_set_error('event_checker_group',t('sorry blabla'));
        
        }
      }
    }

I hope that helps.

drupal7: using form_set_value()

I am trying to update a value during the validate phase of a node-form, i.e. if the custom validation error is fired, just empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea what the different values mean.

the function is: form_set_value($element, $value, &$form_state)

now i understand that the last value is simply the $form_state, that I am having through the validate function. but what about $element and $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there.

but when I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

[EDIT2]

    //calls when node is being created
    function eventcheck_node_validate($node,$form,&$form_state) {
      //checks if the node type is applicable
      if($node -> type=='article') {
        //checks if field 'field_event_choose' AND either 'field_event_title' 
        //or 'field_event' is supplied, if so, fire form_set_value() and form_set_error()
        if ((array_key_exists('endpoints',$node -> field_event_choose['und'][0])) && 
        (($node -> field_event_title['und'][0]['value']<>'') || (isset($node -> 
        field_event['und'][0]['value'])))) {
        
          //fire away
          $form_set_value(???);
          $form_set_error('event_checker_group',t('sorry blabla'));
        
        }
      }
    }

I hope that helps.

Using form_set_value() in Drupal 7

I am trying to update a value during the validate phase of a node-form, i.e. if the custom validation error is fired, just empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea what the different values mean.

the function is: form_set_value($element, $value, &$form_state)

now i understand that the last value is simply the $form_state, that I am having through the validate function. but what about $element and $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there.

but when I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

[EDIT2]

    //calls when node is being created
    function eventcheck_node_validate($node,$form,&$form_state) {
      //checks if the node type is applicable
      if($node -> type=='article') {
        //checks if field 'field_event_choose' AND either 'field_event_title' 
        //or 'field_event' is supplied, if so, fire form_set_value() and form_set_error()
        if ((array_key_exists('endpoints',$node -> field_event_choose['und'][0])) && 
        (($node -> field_event_title['und'][0]['value']<>'') || (isset($node -> 
        field_event['und'][0]['value'])))) {
        
          //fire away
          $form_set_value(???);
          $form_set_error('event_checker_group',t('sorry blabla'));
        
        }
      }
    }

I hope that helps.

added 853 characters in body
Source Link
alex
  • 373
  • 1
  • 4
  • 14

I am trying to update a value during the validate phase of a node-form, i.e. if the custom validation error is fired, just empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea what the different values mean.

the function is: form_set_value($element, $value, &$form_state)

now i understand that the last value is simply the $form_state, that I am having through the validate function. but what about $element and $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there.

but when I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

[EDIT2]

    //calls when node is being created
    function eventcheck_node_validate($node,$form,&$form_state) {
      //checks if the node type is applicable
      if($node -> type=='article') {
        //checks if field 'field_event_choose' AND either 'field_event_title' 
        //or 'field_event' is supplied, if so, fire form_set_value() and form_set_error()
        if ((array_key_exists('endpoints',$node -> field_event_choose['und'][0])) && 
        (($node -> field_event_title['und'][0]['value']<>'') || (isset($node -> 
        field_event['und'][0]['value'])))) {
        
          //fire away
          $form_set_value(???);
          $form_set_error('event_checker_group',t('sorry blabla'));
        
        }
      }
    }

I hope that helps.

I am trying to update a value during the validate phase of a node-form, i.e. if the custom validation error is fired, just empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea what the different values mean.

the function is: form_set_value($element, $value, &$form_state)

now i understand that the last value is simply the $form_state, that I am having through the validate function. but what about $element and $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there.

but when I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

I am trying to update a value during the validate phase of a node-form, i.e. if the custom validation error is fired, just empty one of the fields.

for the last 30 hours I am trying to make sense of the drupal api, but I am giving up. I just do not seem to get the idea what the different values mean.

the function is: form_set_value($element, $value, &$form_state)

now i understand that the last value is simply the $form_state, that I am having through the validate function. but what about $element and $value?

I was trying a lot and apparently the desired value resides in $form['field_name']['und'][0]['value']['#value'] and only there.

but when I am trying form_set_value($form['field_name']['und'][0]['value']['#value'],'foo',$form_state) it raises

    Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be an array, string given, called in /includes/form.inc on line 2436 and defined in drupal_array_set_nested_value()

and when I am trying:

    $newvalue = $form['field_name']['und'][0]['value'];
    $newvalue['#value']='foo';
    form_set_value($form['field_name']['und'][0]['value'],$newvalue,$form_state);

it raises:

    Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()

Thanks for any help!

[EDIT]

My complete function is:

    function hook_node_validate($node,$form,&$form_state) {
      if(fancy_stuff){
        form_set_value();
        form_set_error();
      } 
    }

[EDIT2]

    //calls when node is being created
    function eventcheck_node_validate($node,$form,&$form_state) {
      //checks if the node type is applicable
      if($node -> type=='article') {
        //checks if field 'field_event_choose' AND either 'field_event_title' 
        //or 'field_event' is supplied, if so, fire form_set_value() and form_set_error()
        if ((array_key_exists('endpoints',$node -> field_event_choose['und'][0])) && 
        (($node -> field_event_title['und'][0]['value']<>'') || (isset($node -> 
        field_event['und'][0]['value'])))) {
        
          //fire away
          $form_set_value(???);
          $form_set_error('event_checker_group',t('sorry blabla'));
        
        }
      }
    }

I hope that helps.

added 221 characters in body
Source Link
alex
  • 373
  • 1
  • 4
  • 14
Loading
Source Link
alex
  • 373
  • 1
  • 4
  • 14
Loading