Firebase电子邮件和密码验证网站

时间:2017-12-04 17:21:35

标签: javascript php jquery html firebase

我是Firebase的新手,我正在努力弄清楚如何为特定任务设置它。任务是让每个用户提交表单以记录他们的库存。我认为设置它的最佳方式是:

用户

  • 用户1
  • 用户2

广告

  • 用户1项目1
  • 用户1第2项
  • 用户2第1项
  • 用户2第2项

但是,我无法将库存表单提交到数据库。我认为它与身份验证有关,因为用户注册表单有效。

我的规则:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

我的表单页面:

<?php
require ($_SERVER['DOCUMENT_ROOT'] . '/Emily-Projects/auth/tire/variables.php');

?>
<!DOCTYPE html>
<html>

<head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">

            <link rel="stylesheet" href="../../../inc/styles/css.css">

</head>

<body>
    <div class="container">
    <div class="content" style="background-color: white;">
        <div id="heading">
            <h1>Add A Tire<h1>
        </div>
        <form>
            <div id="1" class="form-sections">
                <div class="input-div">
                <label for="width" class="label">Width</label>
                <select name="width" id="width" type="select"  class="input">
                    <option value="">---</option>
                            <?php foreach ($tireWidths as $width) {?>
                                <option value="<?php echo $width;?>"><?php echo $width;?></option>
                            <?php } ?>

                </select></div>
                <div class="easy-div">
                    <div>
                                <?php foreach ($width100s as $width){ ?>
                                    <z data-role="button" data-val="<?php echo $width;?>" class="width-sm"><?php echo $width?></z>
                                <?php } ?>

                                </div>
                            <div>
                                <?php foreach ($width200s as $width){ ?>
                                    <z data-role="button" data-val="<?php echo $width;?>" class="width-sm"><?php echo $width?></z>
                                <?php } ?>

                            </div>
                            <div>
                        <?php foreach ($width300s as $width){ ?>
                                    <z data-role="button" data-val="<?php echo $width;?>" class="width-sm"><?php echo $width?></z>
                                <?php } ?>
                            </div>
                    </div>
            </div> <!-- closing div#1-->
            <div id="2" class="form-sections">
                <div class="input-div">
                    <label for="aspect" class="label">Aspect Ratio</label>
                    <select class="input"  name="aspect" id="aspect">
                                <option value="">---</option>    
                        <?php foreach ($aspects as $aspect) {?>
                                        <option value="<?php echo $aspect;?>"><?php echo $aspect;?></option>
                                    <?php   }?>

                            </select>
                </div>
                <div class="easy-div">
                    <div>
                                    <?php foreach ($aspectsTop as $a){ ?>
                                    <z data-role="button" data-val="<?php echo $a;?>" class="aspectVal"><?php echo $a;?></z>
                                <?php } ?>
                            </div>
                            <div>
                                <?php foreach ($aspectsBottom as $a){ ?>
                                <z data-role="button" data-val="<?php echo $a;?>" class="aspectVal"><?php echo $a;?></z>
                                <?php } ?>
                            </div>
                    </div>
        </div> <!-- closing div#2-->
            <div id="3" class="form-sections">
                <div class="input-div">
                    <label class="label" for="rim">Rim Diameter</label>
                    <select id="rim" name="rim" class="input">
                                <option value="">---</option>
                                <?php foreach ($rimDiameter as $rim){ ?>
                                <option value="<?php echo $rim;?>"><?php echo $rim;?></option>
                                <?php } ?>
                            </select>
                </div>
                <div class="easy-div">
                    <div>
                                <?php foreach ($rimDiaTop as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="rimVal"><?php echo $r;?></z>
                                <?php }?>
                        </div>
                        <div>
                                <?php foreach ($rimDiaBottom as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="rimVal"><?php echo $r;?></z>
                                <?php }?>
                        </div>
                </div>
            </div> <!-- closing div#3-->
            <div id="4" class="form-sections">
                <div class="input-div">
                    <label class="label" for="manufacturer">Manufacturer</label>
                    <select class="input" name="manufacturer" id="manufacturer">
                            <option value="">---</option>
                            <?php foreach ($manufacturers as $m) { ?>
                            <option value="<?php echo $m;?>"><?php echo $m;?></option>
                            <?php } ?>
                        </select>
                </div>
                <div class="easy-div">
                        <div id="manu-group-one">
                                <?php foreach ($manufacturersOne as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="manVal"><?php echo $r;?></z>
                                <?php }?>
                            </div>
                            <div id="manu-group-two">
                                <?php foreach ($manufacturersTwo as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="manVal"><?php echo $r;?></z>
                                <?php }?>
                            </div>
                            <div id="manu-group-three">
                                <?php foreach ($manufacturersThree as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="manVal"><?php echo $r;?></z>
                                <?php }?>
                            </div>
                            <div id="manu-group-four">
                                <?php foreach ($manufacturersFour as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="manVal"><?php echo $r;?></z>
                                <?php }?>
                            </div>
                            <div id="manu-group-five">
                                <?php foreach ($manufacturersFive as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="manVal"><?php echo $r;?></z>
                                <?php }?>
                            </div>
                            <div id="manu-group-six">
                                <?php foreach ($manufacturersSix as $r) { ?>
                                <z data-role="button" data-val="<?php echo $r;?>" class="manVal"><?php echo $r;?></z>
                                <?php }?>
                            </div>
                </div>
            </div> <!-- closing div#4-->
            <div id="5" class="form-sections">
                <div id="5a" class="inner-B"><div class="input-div"><label class="label" for="model">Model</label>
                <select id="model" name="model"  class="input">
                    <option value="">---</option>   
                    <option value="test">Test</option>
                </select>
                </div>
                <div class="easy-div">EASY BUTTONS</div>
                </div><!--closing A -->

                <div id="5B" class="inner-A"><label class="label" for="weight">Shipping Weight</label><input type="text" name="weight" id="weight" class="input"></div><!--closing B -->
            </div> <!-- closing div#5-->
            <div id="6" class="form-sections">
                <div id="6A" class="inner-C">
                    <div class="input-div">
                        <label class="label" for="trim">Trim</label>
                        <select name="trim" id="trim" class="input" >
                            <option value="">---</option>
                            <option value="test">Test</option>
                        </select>
                    </div>
                    <div class="easy-div">EASY BUTTONS</div>
                </div><!--closing A -->
                <div id="6B" class="inner-D">
                    <label class="label" for="cost">Tire Cost</label>
                    <input name="cost" id="cost" class="input">
                </div><!--closing B -->
                <div id="6C" class="inner-E">PICTURES
                <div class="pix">

                <input id="browse" type="file" onchange="previewFiles()" multiple>
                <div id="preview"></div>

                </div>
                </div><!--closing C -->
            </div> <!-- closing div#6-->
            <div id="7" class="form-sections">
                <div id="7A" class="inner-D">
                    <div class="label">Run Flat?</div>
                    <div class="input"><input type="radio" name="runflat" value="yes"> Yes  <input type="radio" name="runflat" value="no"> No </div>
                </div><!--closing A -->
                <div id="7B" class="inner-F">
                    <div class="label">Tread Depth</div>
                    <div class="input">
                        <input type="text" name="tread" id="tread" ><br><br>
                        <?php for($i=1; $i<11; $i++){ ?>
                            <z data-role="button" class="treadDepthVal"> <?php echo $i;?></z>
                        <?php } ?>
                        <?php for($i=11; $i<21; $i++){ ?>
                            <z data-role="button" class="treadDepthVal" data-val="<?php echo $i; ?>"> <?php echo $i;?></z>
                        <?php } ?>    <br><z data-role="button"  class="treadDepthVal" data-val=".25">.25 </z>
                        <z data-role="button" class="treadDepthVal"  data-val=".5">.5</z>
                        <z data-role="button" class="treadDepthVal" data-val=".75">.75</z>
                    </div>
                </div><!--closing B -->
                <div id="7C" class="inner-F"><div class="label">DOT Date</div><div class="input"><input type="text" name="dotdate" id="dotdate" required><br>
                <?php for($i=0; $i <10;  $i++){ ?>
                    <z data-role="button" class="dotDateVal" data-val="<?php echo $i; ?>"><?php echo $i;?></z>
                    <?php } ?>
                </div></div><!--closing C -->
                <div id="7D" class="inner-F"><label class="label" for="patches">Number of Patches</label>
                <div class="input">
                <input type="text" name="patches" id="patches" required><br>
                <?php for($i=0;$i<5;$i++){?>
                    <z data-role="button" class="patchVal" data-val="<?php echo $i; ?>" maxlength="4"><?php echo $i;?></z>
                    <?php
                }?></div></div> <!--closing D-->    
            </div> <!-- closing div#7-->
            <div id="8" class="form-sections">
                <div id="8A" class="inner-G"><div class="label">Retail Price</div>
                    <input type="text" id="retailPrice" name="retailPrice" class="input" required>
                </div>
                <div id="8B" class="inner-G"><div class="label">C.U.T. Share</div><div class="input">- $4.99 </div></div>
                <div id="8C" class="inner-G"><div class="label">C.C. Fee</div><div class="input"><?php echo $ccfee;?></div></div>
                <div id="8D" class="inner-G">Not Applicable</div>
                <div id="8E" class="inner-G"><div class="label">Shipping Est.</div><div class="input"><?php echo $shipEst;?></div></div>
                <div id="8F" class="inner-G"><div class="label">My Pay Out</div><div class="input"><?php echo $payOutRetail;?></div></div>
                <div id="8G" class="inner-G"><div class="label">Tire NOT listed on Cheapest Used Tires</div><div class="input"><input type="checkbox"
 name="notListed" id="notListed"></div></div>

            </div> <!-- closing div#8-->
            <div id="9" class="form-sections">
                <div id="9A" class="inner-G"><div class="label">Wholesale Price</div>
                <input type="text" id="retailPrice" name="retailPrice" class="input" required></div>
                <div id="9B" class="inner-G"><div class="label">C.U.T. Share</div><div class="input">- $4.99</div></div>
                <div id="9C" class="inner-G"><div class="label">C.C. Fee</div><div class="input"><?php echo $ccfee;?></div></div>
                <div id="9D" class="inner-G"><div class="label">Buyer&apos;s Bucks</div><div class="input">- $3.00</div></div>
                <div id="9E" class="inner-G"><div class="label">Shipping Est.</div><div class="input"><?php echo $shipEst;?></div></div>
                <div id="9F" class="inner-G"><div class="label">My Pay Out</div><div class="input"><?php echo $payOutWS;?></div></div>
                <div id="9G" class="inner-G"><div class="label">Wholesale ONLY</div><div class="input"><input type="checkbox" name="notListed" id="notListed"></div></div>
            </div><!--closing div#9-->
        <input type="submit" id="submit" onclick="submitClick()"value="Add This Tire">
        </form>
        </div>
    </div> <!-- closing container -->

    <!-- scripts -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
    <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
    <script src="/Emily-Projects/auth/tire/new-add-a-tire.js"></script>
</body>
</html>

我的Javascript:

 //File: new-add-a-tire.js

 // Initialize Firebase
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyAjzWcrR4nvdb4BtP1kMeBPx_-lGeYVkAg",
    authDomain: "cutdb-41c5d.firebaseapp.com",
    databaseURL: "https://cutdb-41c5d.firebaseio.com",
    projectId: "cutdb-41c5d",
    storageBucket: "cutdb-41c5d.appspot.com",
    messagingSenderId: "768551466581"
  };
  firebase.initializeApp(config);


  //Add a Tire to Firebase
    //vars for elements/inputs
  var width = document.getElementById("width");
  var aspect = document.getElementById("aspect");
  var rim = document.getElementById("rim");
  var manufacturer = document.getElementById("manufacturer");
  var model = document.getElementById("model");
  var weight = document.getElementById("weight");
  var trim = document.getElementById("trim");
  var cost = document.getElementById("cost");
  var tread = document.getElementById("tread"); 
  var dotdate = document.getElementById("dotdate");
  var patches = document.getElementById("patches");
  var retailPrice = document.getElementById("retailPrice");
  var wholesalePrice = document.getElementById("wholesalePrice");
  var notListed = document.getElementById("notListed");
  var wholesaleOnly = document.getElementById("wholesaleOnly");




    $('.width-sm').click(function(){ 
            $(width).val($(this).data('val')).trigger('change');
    })
    $('.aspectVal').click(function(){ 
            $(aspect).val($(this).data('val')).trigger('change');
    })
    $('.rimVal').click(function(){ 
            $(rim).val($(this).data('val')).trigger('change');
    })
    $('.manVal').click(function(){ 
            $(manufacturer).val($(this).data('val')).trigger('change');
    })
    $('.modelVal').click(function(){ 
            $(model).val($(this).data('val')).trigger('change');
    })
    $('.trimVal').click(function(){ 
            $(trim).val($(this).data('val')).trigger('change');
    })

    //MAKE WORK
    $('.patchVal').click(function(){ 
            $(patches).val($(this).data('val')).trigger('change');
    })
    //APPEND THESE???
    $('.treadDepthVal').click(function(){ 
            $(tread).val($(this).data('val')).trigger('change');
    })
    $('.dotDateVal').click(function(){ 
            $(dotdate).val($(this).data('val')).trigger('change');
    })

    //btns
  var submitBtn = document.getElementById("submit");
  //Function: submitClick();

  function submitClick(){
    //alert pops up but nothing shows in DB
    window.alert("Works");
    var firebaseRef = firebase.database().ref();
    firebaseRef.child("Tires").set("some value");
  }


  //picture code
  var j = 0;

function previewFiles() {

    if (j < 9) {


        j++;
        alert(j);
        var preview = document.querySelector('#preview');
        var files = document.querySelector('input[type=file]').files;

        function readAndPreview(file) {

            // Make sure `file.name` matches our extensions criteria
            if (/\.(jpe?g|png|gif)$/i.test(file.name)) {
                var reader = new FileReader();

                reader.addEventListener("load", function() {
                    var image = new Image();
                    image.height = 100;
                    image.title = file.name;
                    image.src = this.result;
                    preview.appendChild(image);
                }, false);

                reader.readAsDataURL(file);
            }

        }

        if (files) {
            [].forEach.call(files, readAndPreview);
        }


    } else {
        alert("I want to get in here");
        document.getElementById("browse").disabled = true;
    }
}

0 个答案:

没有答案