Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to use the following line of PHP code in one of my pages:

<input name="from" id="from" value="<?php echo $_GET['from'];?>" type="text" />

But instead of displaying an empty "from" input field (before typing anything into it), it displays <?php echo $_GET['from'];.

Am I missing something?

Clarification: I am entering this line of PHP code (in addition to some HTML) from the Admin's Edit Page (the HTML tab of course, not the Visual one).

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

You can't use PHP in the WordPress back-end editor. Maybe with a plugin you can, but not out of the box.

The easiest solution for this is creating a shortcode. Then you can use something like [input type="text" name"from"] in your editor.

function input_func( $atts ) {
    extract( shortcode_atts( array(
        'type' => 'text',
        'name' => '',
    ), $atts ) );

    return '<input name="' . $name . '" id="' . $name . '" value="' . (isset($_GET['from']) && $_GET['from'] ? $_GET['from'] : '') . '" type="' . $type . '" />';
}
add_shortcode( 'input', 'input_func' );

See http://codex.wordpress.org/Shortcode_API

share|improve this answer
    
Aha! Well, I tried to avoid installing a "contact us" plugin, thinking that it simplest to isolate everything in one "contact us" page, but I guess I can't avoid either a plugin or a function. I have a simple theme based on twentyelven, containing a style.css only and I know how to edit it via Appearance > Editor, but how do I add there a function? –  ef2011 Feb 1 '12 at 21:15
    
You can add functions in your functions.php theme file. So in your theme folder /themefolder/functions.php. If it isn't there you can create one yourself. –  Rob Vermeer Feb 1 '12 at 21:22
    
OK, got it. I actually needed to create an empty functions.php via cPanel and only then it showed up in Appearance Editor (labeled "Theme Functions"). –  ef2011 Feb 1 '12 at 21:28
add comment

Are you trying to enter this form field/PHP output in the post content?

If so, then: no, you cannot do that. WordPress will strip both the form field AND will sanitize the PHP output.

You need to add such content functionally, i.e. directly in the template file, or else via action/filter hook callback.

share|improve this answer
    
No, I am entering this line of PHP code (in addition to some HTML) from the Admin's Edit Page. Does this make a difference? –  ef2011 Feb 1 '12 at 20:52
    
It does make a difference. Can you update your question to indicate 1) what file you are editing, and 2) post your actual code? –  Chip Bennett Feb 1 '12 at 21:01
add comment

Yes, post content are sanitized : all characters are converted to HTML equivalent and therefore no code could be executed. There is plugins that allows to execute code from post content, but it's bad security. You would better explore shortcodes (that create line of pseudo-code leading to execute real PHP code) or customizing theme files.

Shortcode http://codex.wordpress.org/Shortcode_API

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.