php将单个产品传递到具有隐藏字段的购物车

时间:2018-08-20 13:02:32

标签: php forms redirect shopping-cart

我正在尝试将表单重定向到包含相同价格的一种产品的购物车。有一个重定向,如果购物车中的购物车为空,它将转到另一个页面,我希望这种情况不会发生。这是表单代码:

    <form method="post" onSubmit="return varifyForm()">
        <?php
            if( $this->session->flashdata('error_msg') != ''){
        ?>
        <p style="font-weight:bold; color:#F00;"><?php echo $this->session->flashdata('error_msg'); ?></p>
        <?php
            }
        ?>
        <?php
            if( $this->session->flashdata('success_msg') != ''){
        ?>
        <p style="font-weight:bold; color:#0F0;"><?php echo $this->session->flashdata('success_msg'); ?></p>
        <?php
            }
        ?>
          <div class="form-group">
            <label><strong>Name*</strong></label>
            <div class="row">
              <div class="col-sm-6">
                <input type="text" class="form-control" placeholder="First" style="margin-bottom:5px;" id="" name="terms[first_name]" value="" required>
              </div>
              <div class="col-sm-6">
                <input type="text" class="form-control" placeholder="Last" style="margin-bottom:5px;" id="" name="terms[last_name]" value="" required>
              </div>
            </div>
          </div>
          <div class="form-group">
            <label><strong>Password*</strong></label>
            <div class="row">
              <div class="col-sm-6">
                <input type="password" class="form-control" id="" name="password" value="" placeholder="Enter Password" style="margin-bottom:5px;" required>
              </div>
              <div class="col-sm-6">
                <input type="password" class="form-control" placeholder="Confirm Password" id="" name="confirm_password" value="" style="margin-bottom:5px;" required>
              </div>
            </div>
          </div>
          <div class="form-group">
            <label><strong>Email*</strong></label>
            <input type="email" class="form-control" id="" name="terms[email]" value="" placeholder="Email" required>
          </div>
          <div class="form-group">
            <label for="sel1"><strong>User Role*</strong></label>
            <select class="form-control" id="user_role" name="terms[user_role]">
              <option value="Member">Member</option>
            </select>
          </div>
          <div class="form-group">
            <label for="sel1"><strong>Your Cause*</strong></label>
            <select class="form-control" id="cause" name="terms[cause]">
              <option value="<?php echo $causes['user_id']; ?>"><?php _e($causes['nonprofit_name']); ?></option>
            </select>
          </div>
          <div class="form-group">
            <label><strong>Zip Code*</strong></label>
            <input type="text" class="form-control" id="" name="terms[zip]" value="" required>
          </div>
          <div class="form-group">
            <label><strong>Terms and Conditions*</strong></label>
            <div class="checkbox-inline full">
              <input type="checkbox" id="terms">
              <strong>I agree to the</strong> <a href="<?=base_url() ?>termsandconditions" target="_blank"><strong>Terms and Conditions</strong></a>
            </div>
          </div><br>
          <button type="submit" name="btnSignUp" value="signup" class="btn btn-primary"><p style="margin:0;">NEXT</p></button>
        </form>

我一直被困在修理别人的工作上,感谢能提供的任何帮助。让我知道是否需要其他信息。

谢谢!

1 个答案:

答案 0 :(得分:0)

您好,您提到以下示例代码可能对您有所帮助。如果您需要其他帮助,请告诉我。

    if(!empty($_POST['cart'])){//what ever the cart item name please replace with it.
$cart["{item_id}"] = ["quantity"=>"{qty}","price"=>"{fixed _price}"];
    $_SESSION['cart']=$cart;
header('Location: redirect.php'); //replace with your actual redirect page to redirect.php
}else{
    header('Location: redirect_other.php'); //replace with your actual other redirect page to redirect_other.php
}