简体   繁体   中英

Not sure if possible - 2 forms in on script PHP

I'm trying to get two forms into a single script.

The script would allow you to click on a login button and have a form populate, fill out the form and then create cookies. The 2 forms work really well separately but I'm having issues combining them.

The script is about 180 lines so I'm not going to include all of it.

I'll include the main lines though:

<?php 

if (!isset($_COOKIE['email']) || !isset($_COOKIE['password'])) {
    if (!isset($_POST["login"])) {
        // create form buttons here
    } elseif (isset($_POST["login"])) {
        if (isset($_POST["submit"])) {
            // create form
            // php code and create cookies if correct
        } elseif (isset($_COOKIE['email']) || isset($_COOKIE['password'])) {
            echo "hello $name";
        }
    }
}

That's pretty much the jist of it..

The attempt at combining the two is located at:

http://protein.guru/testlogin.phtml

the separate scripts are located at:

http://protein.guru/signin.phtml

http://protein.guru/login.php

My only 2 questions are:

Is it possible to do so with my current format using php?

If it is not possible with the format I'm using, does anyone have an idea of a format that would work?

I am using the email: tester3651@outlook.com

Password is: meatloaf

Use <button></button> with the same name and different value attribute. Your PHP would be something like:

<?php
$submit = $_POST['submitButtonName'];
if ($submit == 'value1') {
    // do stuff here
} else if ($submit == 'value2') {
    // do other stuff here.
};

You may use a switch case , you may use more if s. Although I can't see the benefit of using the same PHP script to different forms. If they have different fields and values and have a whole differente behave, there should be two scripts, one for each form.

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