I have a custom form that submits and is creating an instance of a node with cck fields. When submiting the form I get an error message.

$form_state ['values'] ['field_festival_start_date'][0]['value'] = '2010-06-03 22:00:00';

drupal_execute ( 'festival_node_form', $form_state, ( object ) $nodeTmp );

I get the error messages

* warning: date_offset_get() expects parameter 1 to be DateTime, null given in .../date/date_elements.inc on line 495.
* warning: date_format() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 498.
* warning: date_format() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 499.
* warning: date_offset_get() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 501.
* warning: date_timezone_set() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 502.
* warning: date_timezone_set() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 503.
* warning: date_format() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 504.
* warning: date_format() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 505.
* warning: date_timezone_set() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 513.
* warning: date_timezone_set() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 514.
* warning: date_format() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 515.
* warning: date_format() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 518.

I have tried with several formats on the input date and I have tried using both date and datetime on the field in cck and the same message is showing. The field is not written to the node.

Anyone who knows how to solve this?

Comments

da_solver’s picture

Hi,
Are you getting an "error" or a "warning"? The message you posted only shows a warning. What is the error message?

cog.rusty’s picture

There seems to be a problem with drupal_execute(). See:

http://drupal.org/node/518816

da_solver’s picture

Hi,
It's a warning not an error. There is a reason why you assign a severity level. Sorry to nit-pick, however if I was a project manager and someone reported a "warning" as an "error", I could accidentally assign resources to the wrong issue.

cog.rusty’s picture

Warnings (unlike Notices) are regular errors. They break code.

da_solver’s picture

Really remedial. By your definition, it's an error not a warning. However, this post is about warnings not errors:

You posted an issue report that details the "warning". http://drupal.org/node/518816

Otherwise it seems to work ok.

Clearly a warning, not an error.

jaypan’s picture

Who cares? You're not a project manager, this isn't a situation where resources are delegated, and the guy has a problem on his site regardless.

Did someone add an extra scoop of pedantic to their cheerios this morning?

Contact me to contract me for D7 -> D10/11 migrations.

cog.rusty’s picture

Definition... Yes, these are tech words, so it is a matter of definitions. For PHP's definitions see http://www.php.net/manual/en/errorfunc.constants.php
"Run-time warnings (non-fatal errors). Execution of the script is not halted."

For example:

$clients = "John, Bob, Dick";
foreach($clients as $client) {
  print $client->name .", ";
  print $client->balance . "<br />";
}

You get a "Warning" about a non-array argument, it prints nothing, and it goes on happily to do the next thing. Obviously it didn't do what you wanted, because the code was not right.

And getting what you wanted is what matters.

da_solver’s picture

Hi,
We use a debugger to solve issues such as this. We set up test/development environments on local development computers and then have our developers trace the code execution via a debugger. I highly recommend you do the same.

We use netbeans (with xdebug), it's free here http://netbeans.org/features/php/index.html . However, the main point is use a debugger to diagnose the issue on a development installation.

Hope that helps.

gallant2’s picture

Hi,
I'm new to Drupal, however I just looked up the function signature for drupal_execute() (Drupal 6). It says pass the second argument (form_state) by reference not value? I don't see anything about a third argument
http://api.drupal.org/api/function/drupal_execute/6.

Please note! I am a project and development manager. It's Sunday afternoon. Therefore, I have the day off, however I am always on call for emergencies. We have an operation team that monitors hundreds of applications with special software. An "Error" message means the operation team goes in to action. They look up recovery procedures, if they don't find a recovery procedure for the "Error", they call me.

A WARNING message means I get a report on Monday. I don't get bothered on my day off. Therefore, where I work, there is a major difference between an ERROR and a WARNING :)

I'm perusing the development forum to get a sense of expertise in the Drupal community. Interesting.

kritro’s picture

OK, Its a Warning, but its an error to me because the date fields in the node was not updated.

Thanks for the replys, I try the patch(es) on http://drupal.org/node/518816 and se what happens

gallant2’s picture

Hi,
You have the wrong number of arguments in drupal_execute. Plus you are passing one of the parameters by value not reference.

http://api.drupal.org/api/function/drupal_execute/6 :

    drupal_execute($form_id, &$form_state)

Your code:
drupal_execute ( 'festival_node_form', $form_state, ( object ) $nodeTmp );

Shouldn't it read:

drupal_execute ( 'festival_node_form', &$form_state);

?

da_solver’s picture

Hi Gallant2,
Of course you are correct. Since the poster fails to pass a reference of the form_state object he's getting unexpected results in the subsequent process. That's why I suggested running the code through a debugger. The poster needs to trace through the code execution to see what's actually happening. Otherwise, you'll get a trail on this forum where the poster asks to have one syntax error after the next cleared.

When you trace through the code, you verify everything runs as expected. You also, see exactly what and where the exceptions occur.

Sometimes it best just to show these folks there is a better method of development.

A lot of the folks here know a lot about Drupal but don't seem to be versed in enterprise development. Trying to enlighten folks. Thus, the questions about error versus warning.

jaypan’s picture

Who cares if people here are versed in enterprise development. This isn't enterprise_development.org, it's drupal.org, and the original poster never made any comments about enterprise development, nor asked any questions regarding it. He asked questions regarding Drupal.

I could start telling you how you are doing things all wrong as far as web development in the publishing industry goes (my line of work), but you really wouldn't care would you. Because it's completely irrelevant.

Contact me to contract me for D7 -> D10/11 migrations.

cog.rusty’s picture

@gallant2, da_solver, all enterprise managers,

About the right syntax of passing arguments by reference, you can check http://php.net/manual/en/language.references.pass.php

About passing a variable number of arguments, check
http://www.php.net/manual/en/function.func-get-arg.php
and also the source of the Drupal function you linked.

I have been there. In PHP, as well as in a few other things, knowing the stuff gets you much further than logic.

druderman’s picture

I was trying to do just the same thing for the first time and just got it going.

drupal_execute() wants the input similar to what a human would enter into the form.
I also find that the form field names used to edit your content type are a good clue to how you should reference the field.
It seems that dates are treated differently.

Viewing the source of my form I see that the input field name is:
[field_startdate][0][value][date]

So in my code I tried:
$form_state['values']['field_startdate'][0]['value']['date'] = '2010/9/01';

Doing this works for me, although you should use whatever input format you used in your form.

letsbuild’s picture

Many thanks, this works for me:
$form_state['values']['field_startdate'][0]['value']['date'] = '2010/9/01';