1

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.

0

Fist 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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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