在wordpress页面中添加隐藏字段

have a custom html form in page:

    <form action="localhost/mail.php" id="contactForm" method="post">
    <ul>
        <li>
    <input type="hidden" name="submitted" value="USERNAME_HERE" /></li>
        <li>
            <button type="submit">Send request</button>
        </li>
    </ul>

</form>

Can I somehow add current logged username name in to value=... ? So when user will click "Send request" button, I will receive his username in email?

Tried use [userinfo field="user_login"] and :

    <?php global $current_user;
      get_currentuserinfo();

      echo 'Username: ' . $current_user->user_login . "
";

?>

But all php code was cut so it is useless :(

Please advise what I am doing wrong.

Thanks!

Generally I use page templates to work with PHP in pages. Once you have your template set up you can do something like this:

<?php
/*
 * Template Name: Custom Form
 * Description: Form with pre-filled username. 
 */

    global $current_user;
    get_currentuserinfo();
?>

 <form action="localhost/mail.php" id="contactForm" method="post">
 <ul>
    <li>
      <input type="hidden" name="submitted" value="<?php echo $current_user->user_login; ?>" />
    </li>
    <li>
        <button type="submit">Send request</button>
    </li>
</ul>

</form>

You'll probably want to copy page.php from your theme into a file called page-form.php for your template, then modify page-form.php. Look for the_content(); and add your custom PHP there.

You can read more about templates here: http://codex.wordpress.org/Page_Templates

Maybe this will help:

<?php

$user_nameField = $_POST['user_name'];



?>





    <form action="localhost/mail.php" id="contactForm" method="post">
        <ul>
            <li>
        <input  name="user_name" type="hidden"  id="user_name"  value="<?php echo $ulog; ?>"></li>
            <li>
                <button type="submit">Send request</button>
            </li>
        </ul>  
</form>

Use this plugin: http://wordpress.org/plugins/shortcode-exec-php/

You will need to create a block of php code in this plugin then put it in your page as short code.

so your php code will look like this:

<?php 
      global $current_user;
      get_currentuserinfo();

      $username = $current_user->user_login;

?>
<form action="localhost/mail.php" id="contactForm" method="post">
    <ul>
        <li>
    <input type="hidden" name="submitted" value="<?php echo $username; ?>" /></li>
        <li>
            <button type="submit">Send request</button>
        </li>
    </ul>

</form>