我看不出一個特定的 html 欄位不發送資料的原因。
我的html:
<form id="login_registro_form" role="form" method="post" action="./controllers/register.php">
<div class="row my-4 justify-content-md-center">
<label class="col-lg-3" for="regName">NOMBRE</label>
<input type="text" class="form-control" id="regName" placeholder="SEGúN APARECE EN EL DNI/PASAPORTE" name="regName">
<div class="invalid-feedback ">El nombre es un campo obligatorio </div>
</div>
<div class="row my-4 justify-content-md-center">
<label class="col-lg-3" for="reg_birthday">CONFIRMA TU TALLA</label>
<select class="form-select" id="talla" nombre="talla" aria-label="Default select example">
<option value="xs">XS</option>
<option value="s">S</option>
<option value="m" selected>M</option>
<option value="L">L</option>
<option value="xl">XL</option>
<option value="xxl">XXL</option>
</select>
</div>
<div class="login_cb justify-content-md-center">
<label for="reg_allergies">ALERGIAS, INTOLERANCIAS O DIETAS ESPECIALES</label>
<input type="checkbox" class="form-check-input " id="reg_allergies" name="allergies" >
</div>
<button id="register_button" type="submit" class="btn btn-primary" >GUARDAR</button>
</form>
雖然這被縮短了,但所有其他輸入欄位都在作業并包含在同一個 div 中
在我的 php 中,我嘗試檢查:
var_dump($_POST);die;
我可以在那里看到除了選項之外的所有其他變數還有一件事。在發送資訊之前,我進行了一些驗證:
$('#login_registro_form').submit(function(e) {
//My validations for the rest of the form
console.log($('#talla').val()); //THIS IS ACTUALLY SHOWING THE INFORMATION
return (errores.length <= 0 );
});
所以資訊在發布之前就在那里,但由于某種原因它沒有被識別為表單的一部分
編輯:我知道我可以使用 jquery 檢索資訊并通過創建一個新欄位來發送它,但我試圖在這里理解我的 html 錯誤。
uj5u.com熱心網友回復:
您沒有給<select>元素一個name="talla" 屬性,因此它不會發送到 PHP 代碼。只有具有name= 屬性的欄位才能將資料發送到PHP 代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/410629.html
標籤:
