Drupal 6 custom submit function to alter submitted node data - drupal

I have written a module that uses hook_form_alter to add a custom submit function to the node form. This function is not intended to remove the original node submit function, it is there simply to alter node data before it is inserted into the database.
The problem is that when I print_r the posted form array from inside my module when a node is added, the array is massive and it seems the posted data repeats numerous times. I need to know, which part(s) of this array I should be altering so that my altered values are inserted into the database.
To expand a little bit, the module works in the following way: My module attaches a custom submit function to the node form. A user submits a node (containing numerous CCK fields). Some of these fields are left empty. My custom submit function finds these fields and adds a value to them. The node is then inserted into the database.
The module and function I am using work perfectly, but I just can't seem to find what part of the submitted array needs to be altered so that the custom data will be inserted by the node module's own submit function. I would post the array but due to the size, it's probably not advisable, although if anyone would like it I could send it somehow.
Finally, I know there are easier ways of doing similar to what I am trying to achieve but unfortunately this is the only option in the circumstances.

Apologies for wasting anyone's time, I was looking at the $form array when in fact the submitted values are stored in $form_state['values'].

Related

Get request data (GET) in a Symfony (5) formType without using data_class

I'm building a formType to filter products on a collection page. You can set multiple select boxes which makes other auto filled or unnecessary. I want to be able to manipulate the formType based on the data like when using a data_class object. I'm not using data_class because the search isn't a persisted object which is saved to the database. I'm using a GET form.
For example 2 select boxes:
category
productType
When setting a category makes some of the productTypes unnecessary. So i want to not show it.
To do so in the formType I need the data of the request (GET) but I can't find a way to do so.
To retrieve data from the form, you can use $form->getData().
As you're in a GET context, I suspect you can take advantage from FormEvents (take a closer look to POST_SET_DATA event) and get rid of values you don't need.
One other thing I would like to point out, is that you still can use some kind of object that's not persisted to DB, like DTO or whatever.
Forms and entities are not related anyhow, neither in the usage nor in the intentions.

form in wordpress that writes to many tables (with different columns)

Currently, I'm using tablepress to output different info using a table format. I want users to be able to add to existing information. I need a form in wordpress that saves user posts to these different tables. How should I go about this? Sorry if I sound stupid but I'm soft on html.
Thanks.
If you want to insert in posts table using custom form, you can use wp_insert_post().
This function inserts posts (and pages) in the database. It sanitizes variables, does some checks, fills in missing variables like date/time, etc. It takes an object as its argument and returns the post ID of the created post (or 0 if there is an error).
Reference : http://codex.wordpress.org/Function_Reference/wp_insert_post

Combining data and form

I am writing a module in Drupal 7, that shows some data from database using theme('table').
It works great and now I would like to add some data filtering by a date and a category using
textfield and a select box.
How do I combine those two?
Your theme function returns the formatted output according to an array you pass as a parameter. So you have to filter the contents of your array before passing it to the theme function. Create your form elements using Drupal's FAPI, in the submit function of your form pass the parameters needed in your page's query string and use these values to filter/create your array before passing it to your theme function. Usually you use these parameters to filter your SQL query to the database itself.
As an example on how to implement this submission function: How to make a form self referencing in Drupal? Or any other options?
Also, check out Drupal's core search and dblog modules as references. The reports page in Database Logging has a filter and the Search module implements a search passing parameters.

Drupal - Rules Condition that node has been updated more than once?

Is it possible to have a Rules Condition that a node has been updated more than once?
I need different email alerts for when content is created and when its updated. The issue is that im using the Multistep module:
http://drupal.org/project/multistep
The Multistep module breaks the node creation form into 2 or more separate pages. One the first page the node is created but unpublished. When you finish all the steps the node is updated and published. I need the email to be sent after the node has had all the steps filled in, as the CCK fields are used in the email. Therefore I cant use Rules inbuilt event of 'After saving new content' and 'After updating existing content'.
How can I differentiate in Rules from when the node is first fully filled in, and when its subsequently updated? One way to do this would be to have different conditions for weather the node has been updated once or more than once. Is this possible and if so, is it the best solution?
Thanks
I think the easiest way to do this would be too look at the URL or referrer like mentioned here, http://drupal.org/node/827728. You'd have to use the Execute PHP functionality and have some knowledge of how to write a short script though.
PROBLEM:
How to test for the number of times a node has been modified.
POSSIBLE SOLUTION:
Include a "counter" field in the CCK that is hidden from the user (via CSS) and auto-incremented each time the node is accessed. Then use the value of this counter in rules conditions.
(See e.g., http://drupal.org/node/1172550 for more details)
PROBLEM:
How to treat a node differently based on whether it is being 'added' for the first time, or 'updated'.
POSSIBLE SOLUTION:
Create a path rule that is conditional on node type.
Trigger the path rule for the node/add page of the specific node type.
Pre-populate fields on the node/add page using the elementdefaults module.

Anyone familiar in Drupal 6 Services module specifically node.save

I can save/update on regular fields but I'm having trouble saving/updating CCK fields. here's an example node.save() XML request - http://pastebin.com/m5ceca16
I'm assuming your XML data mirrors the node object format.
A CCK field 'field_custom' will be accessible via $node->field_custom. Regardless of type and the limit on number of entries, fields are always arrays. If the CCK field only allows one entry, it is $node->field_custom[0].
The indexes below that level depend on the field type. Most, especially numeric and text fields, are 'value' (eg., $node->field_custom[0] = 'foo'). I've used Nodereference fields which use 'nid', from which I would assume Userreference fields use 'uid'.
The structure of your XML seems correct. I would check the structure of a node object on the site (using a var_dump() or the devel module) to make sure all of your array keys and variable names are correct for your field and field type.
2 things to check:
A var_dump of the results of a node_load() doesn't give you the exact format you should use. Your XML must emulate the input format of the node edit form. So while a var_dump might show you several taxonomy terms in an array, the node edit form may expect the taxonomy terms separated by commas. Off-hand I don't see any fields in your example that this would seem to apply to but I mention it anyway.
Your "changed" timestamp must not be in the future, nor must it be too far in the past. The node will not save if this is off by much. This can be an issue if the clocks on one of the computers isn't very accurate. I had an issue where my services server was about 20 seconds behind my services client so all the updates were getting rejected (the server apparently rejected them on the grounds that they were from the future).

Resources