i have found some similar topics on this issue, but nothing for my case:
i send some post data via form, but the $_POST array is always empty (not null). but when i add a "die;" or "exit;" after var_dump($_POST); i can see all data sent.
maybe its relevant to know, that this is inside a (shopware) plugin which is called on "onPreDispatch".
thanks for any help
Your (shopware) plugin probably uses output buffering. Which means it will gather all the ecoes and prints until you call ob_flush() which prints all the buffer.
die() function, apart from everything else, also flushes the buffer when called.
So, if you do ob_flush() after your echo you should get the needed result.
the problem was the redirect, which resetted the post although it was after i read the parameters in the request.
i did not know, that shopware saves the desired data (paymentID) in the database. so i switched my plugin back to "onPostDispatch" (this way it will be called after all other actions, one of them saves the data in db). now i can just read the db and get the same data, which was initially in the post array.
i tried to be "the first" who reads the post, but could not work it out. now i am the last who reads it and it works fine.
thanks for all answers! the clue here was "redirect".
Related
I'm trying to access some data I've sent to this page (pincode.php), by using the $_POST[] array. However, it seems the variable isn't set, even though the network tab shows the data got succesfully sent.
The code I use to get the value from the $_POST[] array (in the pincode.php file):
if (isset($_POST['buy'])) {
$id_buy = $_POST['buy'];
echo $id_buy;
}
The problem is the if-statement doesn't fire, so apperently $_POST['buy'] isn't set.
Does anyone know a possible cause?
UPDATE:
As a test, I've created the file: test.php, with the following content:
This creates the following result and I still don't get the echo:
I am getting the same issue here, am I missing something important?
what I want to do: my contact form 7 is very simple. I have a input field and a submit button. I want to manipulate the data from the textfield instead of (or maybe before, but for now just say, instead of) sending an email. let's say I want to add 1 to the number entered and display it on the screen.
my cf7:
[number* textfield]
[submit "Senden"]
my functions.php: at the end of my functions.php, i have the following code.
add_action("wpcf7_before_send_mail", "wpcf7_datamanipulate");
function wpcf7_datamanipulate($cf7) {
$wpcf = WPCF7_ContactForm::get_current();
if (true)
$wpcf->skip_mail = true;
return $wpcf;
}
this works quite well for skipping the mail. perfekt. Now I want to var_dump or print_r the content of $wpcf so I know where the number is stored I entered earlier.
var_dump($wpcf);
doesn't seem to work in the functions.php - nor does a simple echo.
I also tried to kill the script right after var_dump() with die(), but the content of $wpcf isn't working.
what can I use to display the data I need to work with in my function?
thanks a lot!
When debugging functions.php I use the following:
echo "<!-- DEBUG\n" . print_r($wpcf, true) . "\n-->";
The above puts your print_r data inside a HTML comment, so the page will render as normal. Then just view the source of the page and search for "DEBUG". You'll see your data.
The important bit is the true specified for print_r. This instructs print_r to return a string (which is appended to the comment string) and echo puts it into the html. Once the page is finished rendering, then you can view the comment.
Otherwise, print_r will try and print the data straight away and it may not end up where you want it (or cause that horrible headers have already been sent issue).
Echo from DukeOfAnkh's solution didn't work for me neither. I found this article where is wrote "Note that you can’t ‘echo’ or ‘print’ anything to the screen in this process; it won’t be shown." and mentioned alternative worked:
error_log( print_r( $WPCF7_ContactForm, 1 ) );
I'm using WordPress with Custom Content Types plugin. I have the code in a PHP file which creates a contact form.
The website is http://schools.raci.org.au/competition/ancq/
It was working fine before I migrated it to a new host. I didn't write the original code, so I don't really know how it works.
Here are the relevant files:
Here is the code for the main page: pastebin.com/piaTSVgc
and the code for the form: pastebin.com/xeqsmc5g
here is admin-ajax.php: pastebin.com/eFx2JFJu
here is the function where register_interest_form lives: pastebin.com/knrChkSP
here is functions.php: pastebin.com/hru5LkQR
Thanks in advance!
Its working from.
When we submit form. there is ajax request is been processing and getting 0 in response.
The default response from admin-ajax.php is,
die( '0' );
...by adding your own exit() or die() after returning your desired content prevents the default response from admin-ajax.php being returned as well.
The solution is to add die() to the end of your own ajax function, so you die the script before die('0')
It also generally means that your ajax call has succeeded.
Ultimately, to answer your question, it's meant to work this way. What you are doing by exiting after returning your content is the right thing to do.
details from.
https://wordpress.stackexchange.com/questions/116759/why-does-wordpress-add-0-zero-to-an-ajax-response
I'm working on a system and currently try to implement a script that another (external) system can post to some data so I can store them.
I have no control over the external system - I can just trigger it to post data to my system, giving it my script's url.
Looking at firebug when the post happens, I can see the data posted, something that looks like this:
or (urldecoded)
content={"sex":"male","person":{"name":["chris"],"mbox":["mailto:name.lastename#gmail.com"]}}
&Content-Type=application/json
&auth=DDE233H76BGN
My problem is that when trying to get these parameters in my script, $_POST (and $_REQUEST) is always empty!
I've tried var_dump($_POST) or echo file_get_contents("php://input");, but I don't see any contents.
What am I missing here?
I don't know if response/request headers are needed to get something out of it, I show them here just in case
Edit:
My script now consists of a single line of code, like:
<?php
var_dump($_POST);
?>
or
<?php
echo file_get_contents("php://input");
?>
both of them give me absolutelly nothing :s
The data should be accessed using $arr= json_decode($_POST['content']); ... but you have another problem here.
A detail is missing:
... how can firebug can show you the content of a $_POST that is sent from an external system to your website ( aka: the request does not go through your browser, but probably through an CURL request originating from the external server ). Obviously, I don't get something here.
What I see is a POST request sent from your browser ( in javascript ), made by your website.
Your question miss a crucial detail, I'm just not sure what it is.
Hint:
Try to put an echo 'test'; just before your var_dump, I have the feeling that you may not be debugging the page that is really called by the Ajax POST request that we see in Firebug. A little routing problem ?
Lets look at RFC 1945 to see what "parameter" is
parameter = attribute "=" value
attribute = token
token = 1*<any CHAR except CTLs or tspecials>
CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
So i suppose "Content-Type=application/json" is not a valid part of POST because "-" is not of CTLs
You should try looking at the raw POST data variable:
echo $HTTP_RAW_POST_DATA;
This may be a n00b topic but, anyways, I have been having a rather difficult and strange time with this bug. Basically I was working on a controller method for a page that displays a form. Basically, I was debugging the form's submitted data by var dumping the form input using codeigniter's $this->input->post function like so:
var_dump($this->input->post('first_name'));
Every other day this has worked, but today I was finding that when I dumped post variables to the browser it would return false as if they had no values even though they did have values when I submitted the form. Then I tried accessing the variables through PHP's POST superglobal array directly like so:
var_dump($_POST['first_name']);
and that returned empty as well so then I tried dumping the entire post array like so:
var_dump($_POST);
and it was empty as well despite the fact that I filled out the entire form. Nevertheless, the records in my MySQL database were being updated (which means that the form was submitting even though my $_POST variables appeared empty).
Also, I reasoned that normally, if I var dumped variables in the controller function before a redirect function call that it should give me a 'Headers already sent' error but it never did. It just redirected me to the supposed success page instead of dumping my variables.
So for the about 2 hours I thought that my POST data wasn't being sent and re-checked the code for errors and began commenting out statements one by one until I could find the culprit statement in my script.
Finally, I commented out a chunk of code that sets a success message an redirects, like so:
/*
if($record_updated_successfully)
{
$this->session->set_flashdata('success', $this->lang->line('record-updated-successfully'));
}
redirect('admin/success_page');
*/
and only then did the script start dumping out all my previous variable dumps using codeigniter's $this->input->post function as well as the $_POST superglobal array.
So ok, if the script does indeed redirect me despite the variable dumps sending output before headers are sent then I can see why the $_POST variables would appear empty.
So then the real question is why the script would still redirect despite my sending of output before headers are sent? Has anyone ever experienced this?
Any help with this would be appreciated.
EDIT: with respect to loading the view here's a simplified version of my script looks like
with the debugging var dump statements:
function some_controller_method() {
var_dump($this->input->post());
var_dump($_POST);
// some code
if($this->input->post('form_action') == 'update record') {
// code that runs when the form is submitted
/*
* ...
*/
if($record_updated_successfully)
{
$this->session->set_flashdata('success', $this->lang->line('record-updated-successfully'));
}
redirect('admin/success_page');
}
$this->load->view('my-view-file.php');
}
While I can't be sure, I'm going to assume you were outputting things like the var_dump() in your view file. A view is not executed at the time you call it, for example:
$this->load->view('some_view');
echo "hi!";
In a controller will not result in the contents of some view followed by "hi". It will results in "hi" followed by the contents of some view. The view is actually output after everything else in the controller has run.
This is the only thing that comes to mind with the information you've presented. I'd have to see more code to offer a different diagnosis.
I had "the same" problem and I found an unset() function in a loop in my code. Perhaps this will help.