0

I am using Wordpress for my clients to log into the site, put data in a customized table and save it in a database table. Through the code “example” that I put in funtions.php theme I can return my email at the top of the screen. Code below.

$ current_user = wp_get_current_user ();
$ logado1 = $ current_user-> user_email;  
echo $ logged1;

however through a new blank page I can put the HTML to make it work correctly, including with the css via plugin. But I can't include the php on the page is to retrieve the data from the $ logado1 variable contained in theme / funtions.php. Well, I need to retrieve the data from “$ logado1 email”, and forward it to a next php referenced in.

<form action=" http://localhost/newphp.php" method="post">.

do the treatment and save it in a new table in the “registration” database.

<div class = "divsearch">
<form action=" http://localhost/newphp.php" method="post">
<label class = "textout"> <b> Port 1 </b> </label>
<input type = "text" class = "box1">
<label class = "textout"> <b> Port 2 </b> </label>
<input type = "text" class = "box1">
</form>
<button type = "submit" class = "buttonacept1"> Save </button>
</div>

Does anyone have any solution for this problem ?.

2 Answers 2

0

As said by sabbir you have to create a custom template to use php code, other way is to register a shortcode and the use that shortcode on new page. creating shortcode is much easier, you can paste the code below in functions.php and then use [new_form] shortcode on your page. You can modify the code as per your needs...

function form_shortcode() 
    {   
        if (is_user_logged_in()) {
            $current_user = wp_get_current_user ();
            $logado1 = $current_user->user_email;  
            ob_start();         
        ?>
            <div class = "divsearch">
                <form action=" http://localhost/newphp.php" method="post">
                    <label class = "textout"> <b> Port 1 </b> </label>
                    <input type = "text" class = "box1">
                    <label class = "textout"> <b> Port 2 </b> </label>
                    <input type = "text" class = "box1">
                    <input type="hidden" name="user-email" id="user-email" value="<?php echo $logged1 ?>">;
                </form>
                <button type = "submit" class = "buttonacept1"> Save </button>
            </div>
        <?php                               
        }
        $content=ob_get_clean();
        return $content;
    }
    add_shortcode('new_form', 'form_shortcode');
1
  • 1
    thank you very much, it solved my problem perfectly. Commented Jun 27, 2020 at 11:46
0

You can't add php within visual editor or text editor by default. WordPress doesn't allow that. If you need a custom html page as a page you can always use a page template. Read more about page template here.

For minor cases you can use a plugin to add php as shortcode. Insert Php Snippet is a good one. You can read how to use the plugin here.

1
  • thank you very much for the suggestion, or our friend's code below solved perfectly. because with snippet pluggin it caused many errors Commented Jun 27, 2020 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.