admin管理员组文章数量:1122832
Edit: I have fixed my original issue, please skip to the body for my last remaining issue.
I need to make a plugin. That displays an input field to the user, takes that input field data and passess it to a php function, and then reloads that page and displays what ever the user has typed in.
What I have in my plugin file
function testytest($val1,$val2)
{
return $val1;
}
function awepop_add_view() {
$idPageToTest = 55;
if ( isset($GLOBALS["post"])
&& ($GLOBALS["post"]->ID === $idPageToTest)
) {
echo '<div class="row"><div class="col-md-6 col-md-offset-3"><div class="alert alert-success" role="alert"><p style="text-align: center;">
<form action="" method="get">
Host Name:
<input type="text" name="val1" id="val1"></input>
<br></br>
or
<br></br>
Ip Address:
<input type="text" name="val2" id="val2"></input>
<br></br>
<input type="submit" name="submit" value="send"></input>
</form>
</p></div></div></div>';}
}
add_filter( 'the_content', 'awepop_add_view', 20 );
#add_action("wp_head", "awepop_add_view");
?>
For what ever reason if I add php code to my echo my site hangs with a 500 error until I remove it. It doesn't matter if I put the code above or below my form.
and the code is this
<?php
if( isset($_GET['submit']) )
{
//be sure to validate and clean your variables
$val1 = htmlentities($_GET['val1']);
$val2 = htmlentities($_GET['val2']);
//then you can use them in a PHP function.
$result = testytest($val1, $val2);
echo '$result';
}
?>
I got it from
I do devops not web stuff Sorry =)
Edit: Now when I hit submit it sends me to my sites homepage, it doesn't reload the page I am on with the users input displayed.
Edit: I have fixed my original issue, please skip to the body for my last remaining issue.
I need to make a plugin. That displays an input field to the user, takes that input field data and passess it to a php function, and then reloads that page and displays what ever the user has typed in.
What I have in my plugin file
function testytest($val1,$val2)
{
return $val1;
}
function awepop_add_view() {
$idPageToTest = 55;
if ( isset($GLOBALS["post"])
&& ($GLOBALS["post"]->ID === $idPageToTest)
) {
echo '<div class="row"><div class="col-md-6 col-md-offset-3"><div class="alert alert-success" role="alert"><p style="text-align: center;">
<form action="" method="get">
Host Name:
<input type="text" name="val1" id="val1"></input>
<br></br>
or
<br></br>
Ip Address:
<input type="text" name="val2" id="val2"></input>
<br></br>
<input type="submit" name="submit" value="send"></input>
</form>
</p></div></div></div>';}
}
add_filter( 'the_content', 'awepop_add_view', 20 );
#add_action("wp_head", "awepop_add_view");
?>
For what ever reason if I add php code to my echo my site hangs with a 500 error until I remove it. It doesn't matter if I put the code above or below my form.
and the code is this
<?php
if( isset($_GET['submit']) )
{
//be sure to validate and clean your variables
$val1 = htmlentities($_GET['val1']);
$val2 = htmlentities($_GET['val2']);
//then you can use them in a PHP function.
$result = testytest($val1, $val2);
echo '$result';
}
?>
I got it from https://stackoverflow.com/questions/15055115/how-to-pass-form-input-value-to-php-function
I do devops not web stuff Sorry =)
Edit: Now when I hit submit it sends me to my sites homepage, it doesn't reload the page I am on with the users input displayed.
Share Improve this question edited May 23, 2017 at 12:40 CommunityBot 1 asked Mar 8, 2017 at 14:19 LeviLevi 1114 bronze badges1 Answer
Reset to default 0Fist off always enable Debug in Wordpress when developing. Second pay attention to how you start and end quotes. I had a echo ' ' with ' in side of it. Taking that out solved my issue.
本文标签: phpTake input from form and pass it to function using a wpplugin
版权声明:本文标题:php - Take input from form and pass it to function using a wp-plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291315a1928697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论