0

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!

Eje
  • 354
  • 4
  • 8
lechnerio
  • 884
  • 1
  • 16
  • 44

2 Answers2

3

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).

Duke0fAnkh
  • 301
  • 2
  • 5
  • unfortunately this did not solve my problem. the content of $wpcf is nowhere to be found in the source code. the page contact form 7 plugin keeps loading. https://imgur.com/916mEgC – lechnerio Oct 17 '17 at 11:15
  • Are you viewing the HTML source of the page? That image is showing the rendered web page. In Google Chrome, right-click on the page and choose inspect. Then from in the Elements Tab, press ctrl+F to search. https://imgur.com/a/6yDk7 – Duke0fAnkh Oct 17 '17 at 11:24
  • yes. i do view the source code of the page. and ctrl+f my way to find "debug" – lechnerio Oct 17 '17 at 11:36
-1

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 ) );

MarkJ
  • 39
  • 6