Home>

Thank you very much for your support.
I want to post a value with javascript and receive it with php, but I can't post it well. A php error also appears.
function postform () is a modified version of what was picked up from the web, and is not well understood.
Anyone who knows how to do it, thank you.

Sender

<head>
        <meta http-equiv = "Content-Type" content = "text/html;charset = utf-8">
        <title>T&E G.K. Work continuation support type A offices (rack)</title>
        <style type = "text/css">
        // ~ Omitted ~
        </style>
    <script language = "javascript" type = "text/javascript">
        function checkStr () {
         // ~ Omitted ~
            }
            function checkMail () {
         // ~ Omitted ~
            }
            function check_kuhaku () {
                var str1 = document.getElementById ("userid"). value;
                var str2 = document.getElementById ("password"). value;
                if ((! str1) || (! str2)) {
                    alert ("Required fields are blank");
                    return false;
                } else {
                    page_jump ();
                    return false ();
                }
            }
            function page_jump () {
                var str1 = document.getElementById ("userid"). value;
                var str2 = document.getElementById ("password"). value;
                postform ('userid', str1);
                postform ('password', str2);
                window.location.href = "customer_registration.php";
                return false;
            }
            function postform (name, value) {
                var form = document.createElement ('form');
                var request = document.createElement ('input');
                form.method = 'POST';
                form.action = 'customer_registoration.php';
                request.type = 'hidden';
                request.id = name;
                request.name = name;
                request.value = value;
                form.appendChild (request);
                document.body.appendChild (form);
                form.submit ();
            }
    </script>
    </head>
    <body>
        
            </br>
            
            <form method = "post">
                 Login ID 
                <input type = "text" name = "userid"
                            size = "25" onchange = "checkMail ()" />
                 password 
                <input type = "password" name = "password"
                            size = "25" onchange = "checkStr ()" />
            </form>
        
    </br>
        
            
            <button type = "submit">Login</button>
            </br>
            
            <button>New registration</button>
        
    </body>
</html>

Destination

<? php
        if (isset ($_ POST ['userid'])) {
            print "POST_userid:". $_ POST ['userid']. "<br/>";
        } else {
            print ("No value for $_POST [userid]");
        }
        if (isset ($_ POST ['password'])) {
            print "POST_password:". $_ POST ['password']. "<br>";
        } else {
            print ("No value for $_POST [password]");
        }
    // ~ Omitted ~

Execution result
Notice: Undefined variable: _POST [userid] value is missing in C: \ xampp \ htdocs \ LUCK \ customer_registration.php on line 44

Notice: Undefined variable: _POST [password] has no value in C: \ xampp \ htdocs \ LUCK \ customer_registration.php on line 49

  • Answer # 1

    postform ()is implemented to execute POST sending process every time it is executed, so

    postform ('userid', str1);
    postform ('password', str2);


    In this calling method, "requests containing only userid" and "requests containing only password" are fired respectively.

    Notice: Undefined variable:is displayed because of double quotes, such asprint ("$_ POST [userid] has no value");This is because the string literal using is passed to print.
    PHP tries to expand a variable if it is contained in a string literal enclosed in double quotes. It is an error to try to expand$_ POST [userid]because there is no such value. (To be more precise, I feel like I'm moss trying to resolve the subscriptuseridfirst)

    If you just want to process it as a string, it must be enclosed in single quotes.
    PHP: Strings-Manual

    print ('$_ POST [userid] has no value');

  • Answer # 2

    I have specified multiple postform () ,
    Every time postform is called, a dummy form is submitted
    Also, it seems that the part with id is competing with the existing id

    sample

    Sender

    
      
      
         Login ID           password               
                

    Destination

    ";
      print "POST_password:". htmlspecialchars ($password). "
    "; }