handling submission with a "Form Maker"-created form - php

I'm using Drupal 7 and HAVE to use the Form Maker (https://drupal.org/project/drupal-form) module. Since it's not a normal form, I don't know how to do something like hooking as Drupal form submission Q/A explains for normal forms.
The available options for "action after submission" for those in-database forms are:
Stay on form.
Link to an article.
Display custom text.
Redirect to an URL.
Is there any way I can handle the form submission? e.g.: Is there a way to reference the form state for the submitted form in the url I specify if using (e.g.) option 4? (or whatever mechanism exists to recover that data by knowing+referencing the submitted record).
BTW I'm a total drupal n00b, and couldnt Find TFM to R (so I can follow the RTM principle) about that special issue in the Form Maker doc.

It looks like this module still uses the form API, so you should just be able to use hook_form_alter() to modify these forms. I'm sure there's some kind of naming convention for the IDs of these forms, which will allow you to apply changes exclusively to form maker forms.
If you need to customize the handling of form submissions, you can include your own submit handler by using the #submit form attribute. Note: the example in the link adds the submit handler to a field in the form, but in most cases I add the submit handler to the form array itself. (i.e. $form['#submit'] = array("submit_callback"))
Edit in response to comments
You do not need to reference a form_id when invoking hook_form_alter(). Instead, you can invoke it globally, which will cause drupal to call your hook on every form. As you can see from the documentation link I provided, the $form_id is passed to the function, and you can use that to conditionally modify the form. Please look at the comments on the documentation page for usage examples.
Unless these forms are being embedded using a third party service, if this module is actually legitimate it will be hooking its forms through the form API. Implement hook_form_alter(), and print off the form_id's that are passed to the function. Go to a page that has one of this forms on it, and see what gets printed.
(Also, [form_id]_form_alter() is not the correct syntax for invoking this hook on specific forms. Should be hook_form_[form_id]_alter(), where hook is your module name.)

Related

How do I make a custom <form> element be used in place of a <form> in a pre-existing plugin?

I am customizing a theme and a plugin in Wordpress. The plugin has a button where a user can click to bring up a form where they can ask a question. I want users to use post questions through this button on this plugin, but I don't fancy the visuals on it. So I thought I'd make a form on my landing page that will post into the plugin's form. If this is a terrible idea in the long run, please feel free to let me know because I am still new to web dev.
So the goal is to create a new form whose aesthetics are to my liking but still use the plugin's built in posting capability. How do I make my form paste into the plugin's form and then submit it? You'll notice that my form has 1 additional field: the add money field. I also need to integrate this into the plugin. If anyone know how to begin modifying the code for this I'm all ears to anything I need to start reading or a general way of how to approach this.
My form
Plugin's form
Summary:
Need to have my form paste to plugn form and submit
Need to add a field to the plugin code that my form can post to similar to how the other fields will do do
You can post from a different form if you get the destination URL or javascript that is handling the original form post. You can use the debugger in Firefox or Chrome to inspect the page contents to see how the form is handled.
Adding the money field will be more complicated because you will need to update the server side handling to accept the additional parameter so that it is not simply ignored or causing errors. How much work this is depends on what the server has to do. It may involve adding a column to the database or creating a new table which you will likely want to do the wordpress way if you want to have something that is maintainable.
Lastly keep in mind, that every time the original plugin is updated, it may bust your add on code unless you create your own plugin from the original.

Put a form on every page of a website with Zend Framework 1

it may seem like a dumb question because I feel like it is when asking it but I can't find anything about it in the doc.
I need to put a form in the header of my website that appears in all pages.
I need that form to be able to be submitted in every page (no surprise here).
I can display my form via the layout function of Zend Framework, but I can't find the equivalent for the back-end of the website to be able to treat it at only one place, site-wide.
I thought it would be possible to put the form validation in the bootstrap but it doesn't seem like it.
Did I miss something or do I have to, at least, put the form validation in all init() function of all my controllers ?
take a look at the plugin documentation
You can write a plugin that handles your request. If you need to have your form processed before any other actions take place, I suggest you use the dispatchLoopStartup() hook.
You should avoid predispatch and postdispatch in this case, because those hooks are called multiple times if you proces multiple actions (by using _forward for instance)

Allow a User to Add Fields to a Form Created With Zend Framework

I'm using Zend Framework and I currently have an existing form using zend-form which functions as required.
I want to add another optional text field to it, but allow the user to choose to display the field and also display it multiple times. e.g. A user registration form with an 'alternative emails' area, allowing the user to add further text fields for each of their email addresses.
Unfortunately, I'm not sure how to go about this. I think sub-forms might be the way forward, but not too sure.
Ideally, once the form is submitted I'd want the data in an array so that I can process it for storing in a MySQL table afterwards.
See this excellent post by Jeremy Kendall on dynamically adding fields to a form:
Dynamically Adding Elements to Zend_Form
Upshot is to use jQuery on the client-side to add fields and maintain a registry of the new fields. Then on the server-side, call a new preValidate() method on the form object which checks the posted registry and adds the required fields into the $form object before standard processing - like isValid() and getValues() - is invoked.
Why don't you make an AJAX call to an addfieldAction() method in which you generate the HTML of another textfield and return that? You can still make use of Zend Form and the whole form can be processed the normal way.

Drupal - Core User Module

I have added a button in the form and upon clicking it performs different set of action. The problem i am facing is that the default form is also submitted and i get the velidation messages like enter email etc.
Please advise.
You cannot hijack a form like that. When a form is submitted, all enabled validate handlers will be called, and if no error is found all submit handlers is called.
If you want to make a multi-purpose form, with different requirements, you need to either create the form yourself and handle the validate, or use an existing form, and replace the existing validation with your own.

Drupal form being rendered before submit action

I have a Drupal module page where I am populating a form with a drop-down that contains a list of available parts of a set of files that the user can upload. Once the user uploads a file of a certain type, it removes that option from the list, and when all the available files are uploaded the form will not be rendered.
The problem is that Drupal is drawing the form before it carries out the submit action, so it appears to the user that the operation didn't work until they reload the page.
What is the common way to deal with this? Setting form_state['redirect'] to go to the page doesn't seem to work.
You modify your form so that it saves some information on the state of the form. Then you add a new case to the beginning of the submit function that returns immediately if you're not done uploading all the files, and it will redraw the form.
function modulename_uploader_form(&$form_stuff=null) {
//the function that sets your form array
$stuff = (isset($form_stuff['values'])) ?
$form_stuff['storage']['done_uploading'] :
false; //if values isnt set, this is the first visit.
$form_stuff['storage']['done_uploading'] = done_uploading();
.... the rest of your form creation function.
function modulename_uploader_submit($form, &$form_stuff) {
if($form_stuff['storage']['done_uploading']) {
return;
}
... rest of the function
make sure to unset the storage variable when you're done processing the form. You can also google multi page forms in drupal.
Setting $form_state['redirect'] in your submit handler will just cause the form to reload, fresh, without the old data. It's a way of clearing out the form so that old values don't hang around as defaults.
You probably want to use $form_state['rebuild'], which gives your form-building functions an opportunity to rebuild the form's actual structure, adding more fields or removing options from other fields after the form submit handlers run.
This blog post has a rough tutorial on doing multiple-stage forms in D6, and the Drupal 5 to 6 upgrade docs on Drupal.org contain a useful overview of how $form_state works and what its various flags are for.
The problem is that Drupal is drawing the form before it carries out the submit action, so it appears to the user that the operation didn't work until they reload the page.
I cannot believe it. Are sure about that?

Categories