我有一个使用此属性设置的表单: enctype="multipart/form-data" 并且当我跳转到 PHP 部分并通过 isset() 函数检查 $_POST 变量是否存在时,它们在完全检查后返回 false表格。不使用 enctype 属性时根本不会发生这种情况
在 Google 或 Stack Overflow 上都没有找到任何解决方案,所以决定自己发帖。
形式:
<form action="../processingShit/register.php" method="post" enctype="multipart/form-data">
<div class="row">
<div id="obligatory_inputs" class="col s12">
<div class="input-field col s6" id="fName_wrapper">
<i class="material-icons prefix">account_circle</i>
<input id="input-fName" value="something" name="fName" type="text" class="validate" maxlength="20">
<label for="input-fName">Nombre</label>
</div>
<div class="input-field col s6" id="sName_wrapper">
<i class="material-icons prefix">account_circle</i>
<input id="input-sName" value="something" name="sName" type="text" class="validate" maxlength="20">
<label for="input-sName">Apellido</label>
</div>
<div class="col s6 input_wrappers">
<div class="input-field col s12" id="userName_wrapper">
<i class="material-icons prefix">account_circle</i>
<input type="text" id="input-userName" value="something" name="userName" class="validate">
<label for="input-userName">Nombre de usuario</label>
</div>
</div>
<div class="col s6 input_wrappers">
<div class="input-field col s12">
<i class="material-icons prefix">email</i>
<input id="input-email" value="something" name="email" type="email" class="validate">
<label for="input-email">E-mail</label>
</div>
</div>
<div class="col s6 input_wrappers">
<div class="input-field col s12">
<i class="material-icons prefix">lock</i>
<input type="password" id="input-password" value="something" name="password" class="validate">
<label for="input-password">Contraseña</label>
<span id="security_label">Nivel de seguridad: <span id="security_show" style="color: grey;"><b><i>?</i></b></span> </span>
</div>
</div>
<div class="col s6 input_wrappers">
<div class="input-field col s12">
<i class="material-icons prefix">lock</i>
<input type="password" id="input-password2" value="something" name="password2" class="validate">
<label for="input-password2">Repetir Contraseña</label>
<span id="matchPW"></span>
</div>
</div>
</div>
<div id="opcional_inputs" class="col s12">
<center><div style="width: 90% !important;">
<div class="input-field col s12">
<i class="material-icons prefix">mode_edit</i>
<textarea id="prDesc_ta" value="something" name="prDesc" class="materialize-textarea" maxlength="150"></textarea>
<label for="prDesc_ta">Descripción de perfil</label>
</div>
<br>
<br>
<div class="input-field file-field">
<div class="btn grey darken-4">
<span>Archivo</span>
<input type="file" value="something" name="prPic">
</div>
<div class="file-path-wrapper">
<input class="file-path" type="text" placeholder="Imagen de perfil">
</div>
</div>
<div class="input-field file-field">
<div class="btn grey darken-4">
<span>Archivo</span>
<input type="file" value="something" name="prPort">
</div>
<div class="file-path-wrapper">
<input class="file-path" type="text" placeholder="Portada de Perfil">
</div>
</div>
</div></center>
</div >
<center>
<button id="sendFormBTN" class=" grey darken-4" type="submit">
REGISTRARSE
</button>
</center>
</div>
</form>
注册.php :
<?php
//returns false
if (isset($_POST["fName"]) &&
isset($_POST["sName"]) &&
isset($_POST["userName"]) &&
isset($_POST["email"]) &&
isset($_POST["password"]) &&
isset($_POST["password2"]) &&
isset($_POST["prDesc"]) &&
isset($_POST["prPic"]) &&
isset($_POST["prPort"])
) {
//my code
}
?>
顺便说一下,有些代码是西班牙语的,它不应该影响您对它的理解。
感谢您的耐心:\
在发布您的真实代码后,我明白了问题所在。
是为了这个:
<input type="file" value="something" name="prPic">
和 $_POST["prPic"]
处理文件时,您需要使用$_FILES
而不是$_POST
.
错误报告会向您显示未定义的索引通知。
看到您没有上传文件,只需删除该输入和相关的isset($_POST["prPic"])
条件。
但是,如果您计划处理文件上传,则需要通过以下参考资料了解如何执行此操作:
这超出了问题的范围。
编辑:
如果您在表单标签中使用 enctype 属性,我更像是在寻找一个错误,该错误会由于某种原因使 $_POST VAR 不存在 – Joseph Fernandez
当不使用 enctype 时它返回 true,因为有一个同名的输入,只是不是正确关联的超全局变量。(摘自我的评论)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句