【问题标题】:php pass single product to cart with hidden fieldphp将单个产品传递到带有隐藏字段的购物车
【发布时间】:2018-08-20 13:02:32
【问题描述】:

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

    <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>

我一直在修复别人的工作,并感谢可以提供的任何帮助。如果需要任何其他信息,请告诉我。

谢谢!

【问题讨论】:

  • javascript 是什么样的?

标签: php forms redirect shopping-cart


【解决方案1】:

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

    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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多