User login

Add onto a form from other sources (like a subform) before submitting

You spend enough time in FAPI and it speaks to you. (UPDATE: but it speaks lies.)

The beginnings of a chance to catch material from the subform and duplicate it for the main form:

this should take care of prefilling places

What hasn't worked:

/* did NOT work */
function wsf_action_combined_action_submit($form_id, &$form_values) {
drupal_set_message('<pre>' . print_r($form_values, TRUE) . '</pre>');
  if (isset($form['#node'])) {
    $node = $form['#node'];
  }
  else {
    $node = array('type' => 'action');
  } 
  drupal_execute('action_node_form', $form_values, $node);
}

Neither did simply:
drupal_execute($form_id, $form_values);

Or a couple other variations. Hrm, harrumph, and hibbidy.

Related in a weird way, and I need a freetagging vocabulary to be able to replace the page title for the Organization content type.

Term Token Does Not Work Until User Edits a content type
http://drupal.org/node/137669

They say there's no way to do it with token.

So again, I need to get in there, somewhere in the form process, and duplicate information I know I have--- take what's been entered into $form['tag'] or whatever and set $form['title'] equal to that (well, form title's #value).

From http://api.drupal.org/api/function/node_form/5

$form['#after_build'] = array('node_form_add_preview');

Is after_build my savior? Stay tuned...

Resolution

Searched words: 
Drupal form pre-submit

Comments

NO, #after_build does not

NO, #after_build does not look like it will help.

validate, on the other hand, may be able to be twisted and abused to suit Agaric's evil needs...

WHY drupal_execute doesn't

WHY drupal_execute doesn't work

and a possible lead on static variables?

And a confirmation of the #validate hunch

All from this morning in #drupal on IRC.

ben-agaric: drupal_execute question: I'm trying to send a form to my custom submit handler, where I want to add some things and then submit the form.
[09:15am] ben-agaric: So I'm just trying to pass $form_values and a form_id to drupal_execute, but that doesn't seem to work-- is there a function for rearranging $form_values so drupal_execute likes them?
[09:17am] ben-agaric: Some of the trial-and-error so far: http://agaricdesign.com/note/add-form-from-other-sources-subform-before-submitting
[09:21am] chx: drupal_execute('action_node_form', $form_values, $node); this seems to be correct one.
[09:21am] chx: have you debugged?
[09:25am] ben-agaric: thanks-- I've been using devel to backtrace php errors, but in this case the form just doesn't work. I don't think I pursued the error messages too much because I wasn't sure what the right approach, I'll track them down now
[09:25am] greggles: seen hunmonk?
[09:25am] Druplicon: hunmonk was last seen in #drupal 10 hours 34 min ago saying 'chx: ping'.
[09:25am] greggles: ben-agaric: hi
[09:26am] greggles: ben-agaric: = benjamin M. right?
[09:26am] ben-agaric: greggles: hola
[09:26am] crazygovemployee joined the chat room.
[09:26am] ben-agaric: Benjamin Maurice Melançon the First, A.D.H.D., to be precise
[09:26am] crazygovemployee left the chat room. (Read error: 104 (Connection reset by peer))
[09:26am] greggles: ha
[09:26am] RobLoach joined the chat room.
[09:26am] greggles: I don't have a crazy squiggle-c on my keyboard, so I dared not try your last name
[09:27am] greggles: and by crazy I mean very cool
[09:27am] ben-agaric: lol
[09:27am] CrackerJackMack joined the chat room.
[09:27am] greggles: did you see my followup about cck_latlon?
[09:27am] greggles: or have any other questions about it?
[09:27am] NikLP: cck_latlon?
[09:27am] ben-agaric: haven't seen it yet, no
[09:28am] greggles: NikLP: it is an abomination - you should use geo module instead
[09:28am] wwwebernet joined the chat room.
[09:28am] greggles: NikLP: geo module provides a cck latlon
[09:28am] greggles: NikLP: and so much more
[09:28am] NikLP: negates gmap module...?
[09:28am] greggles: no
[09:28am] crazygovemployee joined the chat room.
[09:28am] greggles: integrates _with_ gmap module
[09:28am] crazygovemployee left the chat room.
[09:28am] NikLP: I have still got to use gmap/location, which sucks
[09:28am] greggles: (eventually)
[09:28am] NikLP: oh good
[09:29am] NikLP: seems to be a lot of "eventually"s in the mapping module area...!
[09:29am] greggles: NikLP: the sad thing is that there are lots of "eventuallys" and also lots of "I built this piece of junk today that duplicates someone else's work"
[09:29am] NikLP: yeah well... that latter one has a lot to do with tag-less module listings on d.o I feel...
[09:29am] NikLP: to hard to find stuff...
[09:31am] greggles: NikLP: too hard to find stuff, I mostly agree
[09:31am] greggles: tag-less? - http://drupal.org/project/Modules/category/65 - hardly
[09:31am] swill joined the chat room.
[09:31am] rcj_ joined the chat room.
[09:31am] greggles: lots of people are saying "too hard to find stuff" but I haven't seen many "doing X will make it easier to find stuff"
[09:31am] NikLP: well I don't personally have that problem, I'm just quoting back what I heard...
[09:31am] greggles: aside from "adding votes" which is not a reasonable solution IMO
[09:32am] NikLP: is there a reasonable solution tho do you think...?
[09:32am] greggles: the problem isn't high/low rated location modules - it's too many in the first place
[09:32am] NikLP: tru nuf
[09:32am] ben-agaric: I will finish my related_content module... as soon as I'm done with World Social Forum
[09:32am] greggles: ben-agaric: that actually is quite ironic - there are 3 or 4 different "related content" modules
[09:32am] ben-agaric: yes!
[09:32am] Druplicon: http://tinyurl.com/e6m6 maybe you should rephrase your question
[09:32am] ben-agaric: IT is!
[09:32am] greggles: ben-agaric: it is both a symptom and a solution to the problem
[09:33am] chx: Druplicon: forget yes
[09:33am] Druplicon: chx: I've forgotten about yes.
[09:33am] ben-agaric: definitely the former, and I hope the latter
[09:33am] greggles: chx: I agree - but that url is helpful - how about a factoid of "yesno"
[09:33am] chx: Druplicon: yes or no is http://tinyurl.com/e6m6 maybe you should rephrase your question
[09:33am] Druplicon: chx: Okay.
[09:33am] chx: yes or no?
[09:33am] Druplicon: http://tinyurl.com/e6m6 maybe you should rephrase your question
[09:33am] greggles: very good
[09:33am] chx: yes or no.
[09:33am] chx: does not fire.
[09:33am] chx: okay.

[09:42am] ben-agaric: reporting negative progress on messing with user-input form values before submitting - Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 21628 bytes) in /var/www/wsf2008/sites/wsf2008.net/modules/wsf_action/wsf_action.module on line 50 - and if I move the drupal_set_message print values statement that is there, white screen
[09:43am] ben-agaric: So if I may be able to point out the obvious to myself in public...
[09:43am] ben-agaric: if I use form_alter to send a form to a custom submit function, which in turn calls drupal_execute
[09:44am] ben-agaric: drupal_execute will submit the form, which triggers my form_alter, which sends the form to the custom submit function
[09:44am] eaton: Not quite.
[09:44am] ben-agaric: which calls drupal_execute... (I'll stop now)
[09:44am] ben-agaric: No?
[09:44am] eaton: ben-agaric: drupal_execute() isn't called by the FormAPI.
[09:45am] wwwebernet left the chat room. ("Leaving.")
[09:45am] eaton: it's a way of manually, in your prorgam, telling FormAPI, "See this array I'm handing you? Treat it as if a user had just submitted it via their browser."
[09:45am] ben-agaric: Yeah--- I'm inserting drupal_execute into a custom submit function
[09:45am] eaton: Oooooo
[09:45am] eaton: that might be... tricky.
[09:45am] ben-agaric: which leads to the poor results described
[09:45am] eaton: Hmmm.
[09:45am] chx: hmmmm indeed
[09:46am] eaton: tell me it's not calling the same form?
[09:46am] chx: i would save $form_values before doing that
[09:46am] ben-agaric: it certainly is!
[09:46am] ekiczek joined the chat room.
[09:46am] chx: ben-agaric: then you are having an infinite loop
[09:46am] ben-agaric: yes, i did finally figure that out
[09:46am] chx: ben-agaric: use a static var to avoid
[09:46am] ben-agaric: occasionally white screens do communicate a bit
[09:47am] • eaton grins.
[09:47am] ben-agaric: what I'm trying to do is take my combined form (which works) -- it's an organic group created at the same time as the first post to the organic group-- but I'd like to duplicate and otherwise mess with some fields between them before submitting.
[09:47am] ben-agaric: So a static variable--- I'm afraid I don't quite follow
[09:47am] eaton: ben-agaric: then you probably want to use a custom validation handler, and use form_set_value() to change the values you want to tweak before it gets submitted.
[09:48am] eaton: maybe? mmm.
[09:48am] ben-agaric: Yeah, that was plan B, hack validate
[09:48am] ben-agaric: I haven't checked if it works for the whole form or just specific parts though
[09:49am] • ben-agaric thinks combining forms is cool and we should have a Drupal way of this sort of hackery
[09:49am] ben-agaric: ... magically appear in the next 5 minutes
[09:49am] eaton: ben-agaric: combining forms is inherently a very tricky thing. The more custom processing there is associated with the form the harder it becomes...

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.