Take input from form and pass it to function using a wp-plugin
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.