hello,

I'm trying to develop a module, but I can't get any value back from the form.
The following doesn't work:

$myvar = $_POST['myvar'];

Does Drupal somehow nix he $_POST array? How should I access the posted vars?

Thanks.

Comments

nevets’s picture

$_POST works fine in Drupal, I am guessing you are trying to get values from a form.

If you are using Drupal functions to construct the form then to get values when the form is posted use

  $edit = $_POST['edit'];
  $value = $edit['variable_name'];

Note that in the Drupal hooks insert, update and validate you can also access the values through the $node parameter like

  $value = $node->variable_name;
beginner’s picture

Thank you nevets for replying.

I found the mistake (see below).

I was using my own form, but I'm going to learn to use Drupal form next. Thank you for the information about it.

--
http://www.reuniting.info/
Healing with Sexual Relationships.

beginner’s picture

It was working when the php was inserted in a page, but not from within the module function.

I forgot to declare:

global $_POST 

Another silly mistake.... but I'm still learning.

--
http://www.reuniting.info/
Healing with Sexual Relationships.

jjeff’s picture

By default, Drupal's form elements are all named "edit[myvar]". And PHP will put all of these variables into an array which becomes accessible through $_POST['edit']. To see what's happening put the line

var_dump($_POST);

into your module. That should tell you exactly what's getting submitted.

Good luck!

-Jeff

--= Jeff Robbins | www.jjeff.com =--

Gunny-1’s picture

Thank you all. Just went through this post found it very useful.