Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have my PHP file included in my views for AJAX. So my problem is that when I try to select the radio inputs with their values I instead get my else statement. I also have my additional CSS and Javascript, but I don't think they are causing the value. It looks like radio buttons may not be made for PHP so if I may not find a solution then maybe I should try to convert them into a checkbox.

Edit: I have managed to get the result of the post and it's returning: [object OBJECT]

Is there a way to get the value of my checked radios for the player account?

Radio's PHP

$usernameError = "";
        $passwordError = "";
        $termsandconditionsError = "";
        $playAccount = "";
        $creatorAccount = "";
        $account = "";
        $error = "";

        if ($_SERVER["REQUEST_METHOD"] == "POST") {
          if (empty($_POST["username"])) {
            $usernameError = "Username is required.";
            echo $usernameError;
          } else {
            $username = signupform_input($_POST["username"]);
          }
          if (empty($_POST["password"])) {
            $passwordError = " Password is required.";
            echo $passwordError;
          } else {
            $password = signupform_input($_POST["password"]);
          }  
        if(!empty($_POST['account'])) {
            $playAccount = $_POST['account'];
        }
         if(!empty($_POST['creatorAccount'])) {
            $creatorAccount = $_POST['creatorAccount'];
        }
        if(isset($_POST['account'])) {
        if(!empty($_POST['account'] || $_POST['creatorAccount'])) {
            $account = $_POST['account'].', '.$_POST['creatorAccount'];
        }
        }   
        
          if(isset($_POST['loginActive'])) {
          if($_POST['loginActive'] == "0" && $usernameError == "" && $passwordError == "" && $termsandconditionsError == "") {
              
              $query = "SELECT * FROM users WHERE username = '". mysqli_real_escape_string($link, $_POST['username'])."' LIMIT 1"; 
              $result = mysqli_query($link, $query);
              if(mysqli_num_rows($result) > 0) {
                    
                  $error = "That username is already taken.";
                  echo $error;
              } else {
                  
                  echo "<p style='color: green'>Hi</p>";
                  $query = "INSERT INTO `users` (`username`, `password`, `plan`) VALUES ('". mysqli_real_escape_string($link, $_POST['username'])."', '". mysqli_real_escape_string($link, $_POST['password'])."', '". mysqli_real_escape_string($link, $account)."')";
                  echo $query;
                  
              }
              
          } 
            }
        } 

Form

 <div class="container" style="margin: 50px;">
          <form method="post" id="signupForm" class="signupForm">
          <h2>Signup</h2>
            <input type="hidden" name="loginActive" id="loginActive" value="0">
            <br>
        <div class="form-group row">
        <label for="username" class="col-lg-16 col-form-label">Username:</label>
        <div class="col-lg-8">
        <input type="text" class="form-control signupInput" name="username" id="username" aria-describedby="username" autocomplete="username" autofocus required>
        </div>
        <p><span class="error"><?php echo $usernameError;?></span><p>
            </div>
      <div class="form-group row">
        <label for="password" class="col-lg-16 col-form-label">Password:</label>
        <div class="col-lg-8">
        <input type="password" class="form-control signupInput" id="Password" name="password" autocomplete="current-password" required>
          </div>
          <p><span class="error"><?php echo $passwordError;?></span><p>
        </div>
        
        <h4>Account Type <i class="far fa-question-circle info" data-toggle="tooltip" data-placement="right" title="Whenever you have all free accounts checked, payment method should be hidden, but if not then click on any paid account and then click back!" height="16px"></i></h4>
        <p>Visit <a href="pricing.php">Plan</a> for pricing details.</p>
          <input type="radio" id="freePlayerAccount" class="free playAccount" name="account" value="1" checked>
          <label for="freePlayerAccount">Player: Free Account $0.00/Mo</label><br>
          <input type="radio" id="proPlayerAccount" class="paid playAccount" name="account" value="2">
          <label for="proPlayerAccount">Player: Pro Account $5.99/Mo</label><br>
          <input type="radio" id="premiumPlayerAccount" class="paid playAccount" name="account" value="3">
          <label for="premiumPlayerAccount">Player: Premium Account $9.99/Mo</label><br>
          <hr>
          <input type="radio" id="creatorFreeAccount" class="creatorAccount" name="creatorAccount" value="4" class="free">
          <label for="creatorFreeAccount">Creator: Free Account $0.00/Mo</label><br>
          <input type="radio" id="creatorProAccount" class="paid creatorAccount" name="creatorAccount" value="5">
          <label for="creatorProAccount">Creator: Pro Account $9.99/Mo</label><br>
          <input type="radio" id="creatorPremiumAccount" class="paid creatorAccount" name="creatorAccount" value="6">
          <label for="creatorPremiumAccount">Creator: Premium Account $14.99/Mo</label><br>
            <hr>
        <div class="hiddenPaymentMethod"> <h5>Payment Method</h5>
          <input type="radio" id="Paypal" name="payment" value="Paypal" class="payment">
          <label for="Paypal">Paypal</label><br>
          <input type="radio" id="creditCard" name="payment" value="CreditCard" class="payment">
          <label for="creditCard">Credit Card</label><br>
          <input type="text" style="display:none;" name="creditCardNumber" id="creditCardNumber" placeholder="Card Number">
          <input type="radio" id="debitCard" name="payment" value="DebitCard" class="payment">
      <label for="debitCard">Debit Card</label>
           <input type="text" style="display:none;" name="debitCardNumber" id="debitCardNumber" placeholder="Card Number"> 
            <br></div>
            <br>
        <input type="checkbox" id="termsAndConditions" class="conditions" name="termsandconditions" value="0">
        <label for="termsAndConditions"> I have read and agreed to the Terms and Conditions <span data-toggle="modal" data-target="#exampleModal"><i class="far fa-question-circle questionMark"></i></span></label>
        <p id="errors"></p>
        <p id="tacError" style="color:red"></p>
        <input type="button" class="btn btn-primary" name="signupButton" id="signUpButton" value="Submit">
    </form>
</div>
 

Jquery

  $("#signUpButton").click(function() { 
                $.ajax({
                    type: "POST",
                    url: "actionSignUp.php",
                    data: "username=" + $("#username").val() + "&password=" + $("#Password").val() + "&termsandconditions=" + $("#termsAndConditions").val() + "&account=" + $(".playAccount") + "&creatorAccount=" + $(".creatorAccount") + "&loginActive=" + $("#loginActive").val()
                }).done(function(result)  {
                        $("#errors").html(result);
                    }).fail(function(xhr, textStatus, errorThrown) {
                    
                        alert("Error Requesting. Please Try Again Later.");
                    
                    });

                }); 
                
                $('input:checkbox').change(
                    function(){
                        if ($(this).is(':checked')) {
                            $(this).val("1");
                        } else {
                            $(this).val("0");
                        }
                    });
                
                 $("#signUpButton").click(function(){
                    
                    if($(".conditions").val() == "0") {
                        $("#tacError").html("Terms and Conditions are required");
                    } else {
                        
                        $("#tacError").html("");
                    }
                })
               
                $('input:radio[name="account"]').change(
                    function(){
                        if ($(this).is(':checked') && $(this).val() == '2') {
                            $(".hiddenPaymentMethod").show();
                        }
                    });
                    
                $('input:radio[name="account"]').change(
                    function(){
                        if ($(this).is(':checked') && $(this).val() == '3') {
                            $(".hiddenPaymentMethod").show();
                        }
                    });
                $('input:radio[name="account"]').change(
                    function(){
                        if ($(this).is(':checked') && $(this).val() == '1') {
                            $(".hiddenPaymentMethod").hide();
                            $("#Paypal").removeAttr('checked');
                        }
                    });
                 $('input:radio[name="creatorAccount"]').change(
                    function(){
                        if ($(this).is(':checked') && $(this).val() == '6') {
               

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
413 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...