Executing PHP Code in Contact Form 7 Textarea

…衆ロ難τιáo~ 提交于 2021-02-08 11:13:01

问题


I've got a contact form 7 form that I'm looking to execute php in the textarea field.

When I tested this with a normal form (ie not a plugin) it worked fine;

 <textarea name="customer-issue" rows="10" cols="40"><?php if(isset($_GET['content'])) { echo $_GET['content']; } ?></textarea>

Does anyone know how you would go about being able to do this in CF7


回答1:


In addition to the code of JpDevs:

He forgot some ' ' at setting the $html variable. This is working:

function cs7() {
    $var=$_GET['content'];
    $html='<p>'.$var.'</p>';
    return $html;
}

add_shortcode('cs7', 'cs7');

Then just add [cs7] to your form.

When you use ' ', you have to write the variables outside by connecting with points:

$result = '<p>'.$var.'</p>';

When you use " ", you can write them inside:

$result = "<p>$var</p>";



回答2:


Kindly have a look at below mentioned link :

https://wordpress.org/support/topic/contact-form-7-input-fields-values-as-php-get-viarables

Hope this helps for you




回答3:


Make the code

$var=$_GET['content']; 

to short code,

and the paste the generated shortcode in your contact form 7 text area

Eg:

functions.php

function cs7() 
{
$var=$_GET['content'];
$html='<p>.$var.</p>';
return $html;
}
add_shortcode('cs7', 'cs7');

add [cs7] in contact form area



来源:https://stackoverflow.com/questions/27817294/executing-php-code-in-contact-form-7-textarea

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!