简体   繁体   中英

embed html form to php code

I have a form on on html outside of php...

<form method="post" action="">
<input type="text" name="user"/></br>

<input type="submit" value="submit" name="login"/> 
</form>

then call submit button from php and do this

if(isset($_POST["login"]))
    {

            print <<<this

    <form method="post" action="">
            <input type="submit" name="apply"/>
            </form>
this;


             if(isset($_POST["apply"]))
             { print "it works";}


    }

Alright, so the problem is that, "it works" won't print from the second form thats inside the php. it just takes me back to where i came from. Perhaps it's a dumb question, please help though! thanks

The problem is that by the time you're checking if(isset($_POST["apply"])) the login condition becomes invalid because everything is inside the if(isset($_POST["login"])) .

Try taking the if(isset($_POST["apply"])) outside the login IF.

Your "apply" code exists only INSIDE the login test code. When you submit that second form, there will be NO login form field, because you didn't include an input/textarea of that name in the second form. So the second form submits, there's no login , and the entire inner code never gets executed. You probably want:

if(isset($_POST["login"]))
    {
            print <<<this

    <form method="post" action="" name="apply">
        <input type="hidden" name="login" value="foo" /> <!-- add this line -->
        etc...

I'm not sure to understand what you wanna do with this code but you obviously missed some details :

_You did not set the "action" field in your form tag, so I don't understant how you would like the PHP file to get called ? _Your code if(isset($_POST['login'])) has no sense, you are testing the existence of a value sent by a validation button, you'd rather whrite isset($_POST['user'])

Hoping to have helped you

Your variables are declared in 2 forms, so there will be 2 calls (completely independant) to your php.

So you could have a second submit button inside your second form:

if(isset($_POST["login"]))
{

        print <<<this
<form method="post" action="">
        <input type="submit" name="apply" value="Second"/>
        </form>

this;


}
if(isset($_POST["apply"]))
{ print "it works";}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM