Programmatically submit form / save all nodes After migrating all the content from a drupal 6 installation to a drupal 7 one, I ended up with empty fields in my nodes, that are displayed when viewing the node. 

However if I edit the node without changing anything and save it, the empty fields are gone (at that point the save function populates the database with the proper null values). 

Obviously I can't do that by hand and the solution proposed here: Load and Save nodes with script? doesn't remove the empty fields, even if I actually edit one of the fields. I would like to do this with a php script as I am not familiar at all with Python and the selenium script proposed here: How to programmatically iterate over nodes, load into form, and save the form?.

Now as far as Drupal's form_submit method, how does it actually populate the $form, $form_state variables since I won't be changing anything.

Thanks in advance.
I don't think trying to fake form submissions is a good idea - there is a lot that goes on behind the scenes, and it is easy to get something wrong.

I would suggest instead you implement a script similar to the one you pointed out in Load and Save nodes with script? in which you actually set the missing values to the empty data you require. In that script, after the node_load (and before the node_save) you could do something like:

$empty_value = array(
  'value' =&gt; ''
);
$node-&gt;field_my_custom_field[$node-&gt;language] = array(
  0 =&gt; $empty_value
);


You would need to do this for each field that needs fixing. The value you need for $empty_value will depend on the field type. You could work it out dynamically by calling field_info_field ;  however as your script is a one-off, it's simpler to just set the right value for each field. To know what the right empty value should be, just create a node with the right empty value and then inspect it (eg. using var_dump, dpm, etc.)