It's been a long time since I don't post here, even forgot my username. Sorry if this is the wrong section.

I can't get the $_POST['name'] values sent from an html form on my php file. I've seen lots of similar questions but nothing helped. I have lot's of includes so I believe it's a scope issue, but I can't figure it out.

index.php

print_r($_POST); //Returns nothing, tried other ways too

//lot's of variables being defined

include 'sql_data_handlers.php';
//instantiating some things

sql_data_handlers.php

//some functions retrieving data from sql db and finally:
include($DOCUMENT_ROOT . "page.html");

page.html

//html stuff
<?php
//Some conditions
include($DOCUMENT_ROOT . "comment_form.html");
?>

comment_form.html

<form action="index.php" name="comment_form" id="comment_form" method="post">
    <input type="text" name="name" value="Anonymous" required><br>
    //lot's of inputs
    <input type="submit">
</form>

I used to have action="send_comment.php" but I realized it could be turned into a function so I ctrl+c and adapted send_comments.php to a function on sql_data_handlers.php. The problem is, now I can't get the $_POST values on index.php to use in the function on sql_data_handlers.php (which is included in index.php).

I would use action="my_php_function_from_data_handlers.php($args)" if it was possible, but I guess it isn't. btw, I already tried action="". This may seem pretty messy but this way I only need one .html for the site layout, pages are on the sql and the .php files do all the job.

Complete source of all files (pretty big, still working on it, new to php too): http://pastebin.com/2nRuCpNx

I tried the form from the pastebin and it seems to work fine for me, I get:

Array
(
    [name] => Anonymous
    [email] => 
    [title] => 
    [contents] => 
    [id] => 30
    [pid] => 21
    [cid] => 1
)

I just hardcoded $this->id and $this->pid, so check if there is something wrong in the generated source of page.html, which should be page.php, unless your server is handling .html as .php

Thanks, cereal, you were right, the array was in fact being generated. I overlooked it because page.php refreshed itself whenever the post request was sent, so $_POST variables was lost.

That was it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.