A custom Field with #submit function can't pass value i wrote a custom field and i want to do mini validation just in the custom field.

The only input data are the cellphone textfield. The other form fields all are used for validation.

However, i can't pass the value of the field.

Is there something wrong?

 function cellphonefield_field_widget_form(&amp;$form,&amp;$form_state,$field,$instance,$langcode,$items,$delta,$element)
    {
        $base=$element;

      dpm($items[$delta]['cellphone']);

        $element['cellphone']=array(
             '#type' =&gt; 'textfield',
         '#title'=&gt;t('Enter your Cell phone Number!'),
         '#description'=&gt;t('System will send you a message '),
         '#default_value'=&gt;isset($items[$delta]['cellphone'])?$items[$delta]['cellphone']:'test for this field',
        )+$base;


      $form['send_sms']=array(
             '#type' =&gt; 'submit',
             '#name' =&gt; 'send_sms',
             '#title' =&gt; t('validate your cellphone number'),
           '#value'=&gt;t('Send Me Validate Code'),
         '#weight'=&gt;1,
         '#limit_validation_errors'=&gt;array(
         array('cellphone')),
         '#submit'=&gt;array('send_sms_function'),
        );

      $form['validate_code']=array(
             '#type' =&gt; 'textfield',
         '#name' =&gt; 'validate_code',
         '#size' =&gt; 20,
         '#title'=&gt; t('Enter the validation code !'),
         '#description'=&gt;t('Please check your cell phone sms message and then enter the code in the sms.'),
         '#weight'=&gt;2,

        );

      $form['validate_button']=array(
             '#type' =&gt; 'submit',
             '#name' =&gt; 'validate_button',
             '#title' =&gt; t('validate your cellphone number'),
           '#value'=&gt;t('Validate'),
         '#weight'=&gt;3,
         '#limit_validation_errors'=&gt;array(),
         '#submit' =&gt; array('send_sms_function'),
        );

        $form['submit_message']=array(
        '#type'=&gt;'item',
        '#title'=&gt;t('Cell Phone'),
        '#description'=&gt;t('Your phone is been validated!'),
        '#weight'=&gt;4,
      );


        return $element;
    }

    function send_sms_function(&amp;$form,&amp;$form_state)
    {

$cellphone=$form_state['values']['cellphone'];
      dpm($cellphone);
          }
For validating the content of a field there is hook_field_validate(). As example of implementation of that hook in a module, you can look at taxonomy_field_validate(), or number_field_validate().

function number_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &amp;$errors) {
  foreach ($items as $delta =&gt; $item) {
    if ($item['value'] != '') {
      if (is_numeric($instance['settings']['min']) &amp;&amp; $item['value'] &lt; $instance['settings']['min']) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' =&gt; 'number_min', 
          'message' =&gt; t('%name: the value may be no less than %min.', array('%name' =&gt; $instance['label'], '%min' =&gt; $instance['settings']['min'])),
        );
      }
      if (is_numeric($instance['settings']['max']) &amp;&amp; $item['value'] &gt; $instance['settings']['max']) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' =&gt; 'number_max', 
          'message' =&gt; t('%name: the value may be no greater than %max.', array('%name' =&gt; $instance['label'], '%max' =&gt; $instance['settings']['max'])),
        );
      }
    }
  }
}


As far as I can see, fields don't add submission buttons. That is not the purpose of fields, which is to add fields to enter data for an entity (e.g. nodes, users, taxonomy terms).

In your case, the workflow is similar to the following one:


The user enters a cell phone number
The module tells to the remote service to send a verification code to that cell phone number
The user enters the verification code
The module checks the verification code is the expected one


Such workflow can work if it is done in two steps:


When the user first enters the cell phone number, the validation hook can just send the cell phone number to the remote service. It cannot wait the user receives the verification code, and enters it.  
The second time, the user edits the verification code, and the validation hook will check the verification code is the right one.


You have to see if checking the verification code can be done synchronously, or asynchronously.