Applying hidden form value to identify which functions to run on a from handling page

38 Views Asked by At

I'm trying to carry a value from the form into my 'Formhandler' document but I can't get it to work. I tried adding a value (Register) to my html tag but that did not work. I know that it's my "hidden" input field in the form that I need to change, I just can't resolve it myself. This maybe a simple fix but I can't see it and need fresh eyes on this problem. Thank you so much in advance.

<form id="signinform" action="<?php echo url_for('../Private/createuser.php');?>" method="post">
  <input type="hidden" name="action" id="action" value="Register" />
        <div class="formcontainer">
        <div class="formrow">
            <div class="formlabel">
            Email 
            </div>
            <div class="formfield">
            <input type="text" name="Email" id="Email" class="required" />
            </div>
        </div>
        <div class="formrow">
            <div class="formlabel">
            First Name 
            </div>
            <div class="formfield">
            <input type="text" name="First_name" id="First_name" class="required" />
            </div>
        </div>
        <div class="formrow">
            <div class="formlabel">
            Surname
            </div>
            <div class="formfield">
            <input type="text" name="Surname" id="Surname" class="required" />
            </div>
        </div>
        <div class="formrow">
            <div class="formlabel">
            Password 
            </div>
            <div class="formfield">
            <input type="password" name="Password" id="Password" class="required" />
            </div>
        </div>
        <div class="formrow">
            <div class="longformlabel"><input type="submit" value="Register" class="formbutton" /></div>
        </div>
        </div>
    </form>

Then the form handler code is;

    if($_POST['action']=='Register') {




        //VALIDATION------------------------------------------------------------------------------------------

        $validated = new FormValidator();
        $validflag=true;

        if($validated->validateItem($_POST['Email'], 'email')) {
                $email=$validated->sanatizeItem($_POST['Email'], 'string');
        } else {
            $validflag=false;   
        }



    //END VALIDATION------------------------------------------------------------------------------------------  


        if($validflag=true) {

                $usercheck=mysqli_query($db,"SELECT * FROM `Users` 
                                    WHERE `Email`='{$_POST[$email]}'");

                                if(mysqli_num_rows($usercheck)>0) {
                                        $_SESSION['message']="Email address already in our database - please login or try registering a new account.";
                                        header("location: signup.php" . $processtext);  
                                    }


            $bcrypt = new Bcrypt(15);
            $salt=$bcrypt->getSalt();

            $hash = $bcrypt->hash($_POST['Password'],$salt);

            $sql1 = "INSERT INTO Users ";
            $sql1 .= "(Email, Password) ";
            $sql1 .= "VALUES (";
            $sql1 .= "'" . $email . "',";
            $sql1 .= "'" . $hash . "',";
            $sql1 .= ")";

            $sql = "INSER INTO saltuser ";
            $sql .= "(Email, Saltstring) ";
            $sql .= "VALUES (";
            $sql .= "'" . $email . "',";
            $sql .= "'" . $salt . "'";
            $sql .= ")";

            $result = mysqli_query($saltdb, $sql);
            $result1 = mysqli_query($db, $sql1);

            } else {
                // INSERT failed
                    echo mysqli_error($db);
                    db_disconnect($db);
                    exit;   
                }


    }

The error on the logs from the formhandler say that 'action' is undefined. Please help.

0

There are 0 best solutions below