+1  A: 

The return you get is because you are accessing a string, and not an array.

$string = "ABCDEFG";
// This would print "A".
print $string[0];

To notice then that a submission handler takes the submitted values from $form_state['values'], not from $form.

kiamlaluno
Sorry, I was trying lots of different things to try to get this to work. I posted the wrong snippet..
cinqoTimo
@kiamlaluno - Not sure I follow you. If I'm in the wrong array - why can I get the first letter of the value I need? Can you show me what you mean by $form_state['values']
cinqoTimo
See [`user_edit_submit()`](http://api.drupal.org/api/function/user_edit_submit/6), [`book_outline_form_submit()`](http://api.drupal.org/api/function/book_outline_form_submit/6), and [`comment_form_submit()`](http://api.drupal.org/api/function/comment_form_submit/6); none of those submission handlers get the submitted values from `$form`. As per the error you are describing, the problem is using a string thinking it is an array; in both the cases, `$variable[0]` is a valid expression, but for a string it would return the first character (which is not what you want, in this case).
kiamlaluno
What is posted is accessing the correct value - I can see it in the array, and I am able to get the first character. As for accessing a string like it is an array, I understand that, but when I leave off the index it prints nothing, so it is not as simple as your example suggests.
cinqoTimo
+1  A: 

Try this instead, I deleted my previous answer once I really looked at the code and noticed I was way off before. There seems to be a lot of redundant arrays created that in my opinion are just confusing the issue. Does this work?

$fromDate = $form[0]['#post']['field_bill_start'][0]['value']['date'];
drupal_set_message("From Date = ".$fromDate);

EDIT:

Updated the code to have another try

acqu13sce
@acqu13sce Thanks, I agree about the needless arrays. What you provided prints - From Date = ""(nothing) and From Date2 = Array
cinqoTimo
I've updated the code, would you mind trying again?If the output you have in your question is coming from the print_r($fromDatePRE) statement then this new code should work I think
acqu13sce
@acqu13sce - Thanks for having a second look. I know that looks right but it's null. I'm thinking of just using a textbox (which I can easily capture the value!?) and use a Jquery calendar to set the value.
cinqoTimo
+1  A: 

Hi cinqoTimo, I think you just need to print $form['field_bill_start'][0]['#value'].

Update: print directly the $form['field_bill_start'][0]['#value'], don't add it to a variable or array.

João Guilherme
That prints "Array"
cinqoTimo
@João Guilherme - I updated my post with the results of a print_r. I thought I could add the array levels like shown.
cinqoTimo
+1  A: 

You should use the value submitted by the user which is on the $form_state;

I tested with a single date field, instead of a datefield with 2 values. But this should work just fine anyways. I might have the naming of your field incorrect, but you can check out the values on $form_state['values'], where you should find your field listed.

Anyways the code would look something like this:

function billing_submit_function($form, &$form_state) {
  $from_date =  $form_state['values']['field_bill_start'][0]['value'];
  $from_date_string = format_date(strtotime($from_date), 'custom', 'D d/m/Y');
  $from_date_2 =  $form_state['values']['field_bill_start'][0]['value2'];
  $from_date_string_2 = format_date(strtotime($from_date_2), 'custom', 'D d/m/Y');

  drupal_set_message("From Date = ".$from_date_string);
  drupal_set_message("From Date2 = ".$from_date_string_2);
}
googletorp
@googletop - You are correct - what you posted pulls the correct value.
cinqoTimo

related questions