How to get url data of form using post method - wordpress

In wordpress, I'm using a template, which is used to store url data from sender page in database. This task is completed well when I use GET method for submitting the form, but when I use POST, then the whole $_POST array is empty in my template. What is the reason for that and how can I solve it?

Related

Get some html form data (or Object) in getServerSideProps() in NEXTJS

I need to get some form data submitted from a NextJS page to another (server side rendered) page in it getServerSideProps function. basically the api that i need call in the getServerSideProps() needs those data to be passed. thought of using localStorage/sessionStorage to store data on the form page and retreive in the function but this wont work as it renders on server. Any Help ?
You can forward the form data fields as query params, or create an object with the form fields and then base64 encode the object, add that string in the query params.
In the next page you can access the params from query in context parameter of the getServerSideProps and then decode the base64 data to retrieve the form fields

Meteor: Best way to create a new document in a collection before visiting a route?

Every time a user visits a specific route, I'd like for a new document to get created that will act as a "draft" that the user will edit until they decide to publish it.
Another way to think about this is that I want to redirect a user to a new page displaying the document after a successful insert of the document.
When I phrase it like that, I think I've basically answered my own question. In this case I would just call a Meteor method that creates and inserts the new document, then in the callback method I would use iron-router's Router.go method to redirect to the url using the new _id as a parameter. Is there a better way?
It's a bad idea to get collection created automatically upon visiting a route. What happen if user visit the route unintentionally?
Nevertheless, you can achieve it by inserting a document on publish function and it will get created upon Meteor.subscribe.
Meteor.publish('test-draft', function(options){
var _id = Test.insert({a: 'b'});
return Test.find({_id: _id})
})
If I understand what you're doing correctly, I think the easiest thing would be to just create an object and put it in a Session variable and not mess with creating a document in a collection until you're done editing it.
You can create the object and stick it into Session in Templates.myTemplate.rendered = function() { ... }. And then when it's been satisfactorily edited and submitted pass the Session variable to a Method that inserts it as a new document.

Drupal 7 - Form API Custom Module

I have a form that calculates two values, form works perfectly, however i'm having some problems working out how I can calculate the two values and return the answer as rendered HTML so I can style it all nice and pretty for the user to see.
All help will much appreciated. Thanks.
In a Drupal form there are three types of callback that are normally necessary to create a form:
The form builder is the function that builds the form using an array the form API understands
The form validation handler is the function that validates the values submitted from the users
The form submission handler is the function that acts on the values submitted from the users
Of those functions, the one that outputs the result of the calculation done on the values submitted from the users is the last one. Normally, the form submission handler saves the data in the database, and show a message to the users through drupal_set_message(), but it could also simply show the result of the operations done on the entered data.
Since Drupal 7, the output of a form submission handler, as well as the output produced from a menu callback, can be a rendering array, and not a string. A rendering array has the pro of being easily altered from third-party modules through hook_page_build(), or hook_page_alter().
node_view() is an example of menu callback that returns a rendering array, and not a string.
If it's just a message you want then you should look into drupal_set_message. It allows you to set a message like this:
drupal_set_message(t('Hello, world.'),'myClass');
Which outputs HTML like this:
<div class="messages myClass">Hello, world</div>
That would be a very simple way to set a message for the user to see once the form is submitted. If you need something a little more advanced, look into my answer here and this Drupal answer here.

"Tokenized email action" is not picking up my tokens

I'm having some problems setting up a tokenized email to use the tokens I've created in my module. I am using this in a tokenized email [example-contact]. I've implemented the example_token_values() and example_token_list() in my module and I've also created a trigger in my module. My module has a form, created with the form API, that gets stored in a custom table. My tokens are listed when I view all available token so I know that example_token_list() is working but when example_token_values() is called $type doesn't come up as equal to 'example'.
I need to pull information from the submitted form and display them on the tokenized email that is sent out. Am I missing a function? The Trigger I created is working and fires when the form is submitted and the Action is sending out the email the problem is that the tokens are not being replace with the form's values.
Is there a function that I need to implement that will call example_token_values("example",$form)?
An implementation of hook_token_values() can use any values for $object; if the module needs to use the value of $form passed to one of its functions, it can use it.

How do I display data from an external database in Drupal?

I am building a custom module that will allow my users to do a simple query against an MS SQL database. I've built the form using hook_form() and have gotten validation to work.
I'm planning on retrieving the data from hook_form_submit(), but once I've done that, how do I append it below the form? It does not appear that I have access to $output from hook_form_submit(). I'm at a loss as to what to do next.
Thanks
Dana
When you are rendering the form you should check for $form_state['values'] to see if the user has already submitted a form when you're rendering the form. Then you could paint the form results in the same step as painting the form.
The first time the user loads the form page the $form_state variable won't contain any submitted form info so you can render an empty results table.
There's a good illustration of the Drupal Form API workflow on Drupal.org here: Form API Internal Workflow Illustration
The problem in trying to output data in the hook_form() method is that the method gets invoked twice which clears the post values the second time through. Throw a dpm($form_state) in the hook_form() function and you'll see two sets of post data. One with values and one without.
So after dissecting the built in Search module, which pretty much operates exactly the way I want my form to work, I figured out how this is done. Well, at least one way you can do it.
What Search module does is take the values from $form_state in hook_form_submit() and pastes them into the URL, then it sets the $form_state['redirect'] to that new URL, effectively storing those variables in the URL and changing the POST to a GET.
Now, in the callback, they extract those values from the URL, do the search on them, THEN they call drupal_get_form(), append the results to the end and return it.
There's another solution HERE where they use SESSION to store the values until the second trip through. Weird, but it works.

Resources