我有一个html表单,我通过PHP邮件发送它。 所有领域似乎都很完美但只有一个!
问题是,我从我的html中的按钮填写了一个文本字段并使用简短的javascript函数。你认为这会以任何方式干扰php代码吗?我遇到问题的文本字段是:
input type="text" name="txtnomtour" id="txtnomtour"
坦克你的帮助!
这是我的工作:
function showcap(nom,tour) {
var nombretour1 = tour;
var div = document.getElementById(nom);
div.style.display = "block";
document.getElementById('txtnomtour').value = String(nombretour1);
}
#btnenviar{
border:solid;
border-width:1px;
border-color:#6C0;
background-color:#91B31A;
border-radius: 20px;
padding: 5px 10px 5px 10px;
cursor:pointer;
box-shadow: 0px 2px 4px #000;
text-shadow: 1px 1px 2px #000;
color:#fff;
}
#btnenviar:hover{
background-color:#829A1F;
}
.botonredondo{
transform: translateX(30%);
background-color:#690;
background: linear-gradient(#F00,#900);
border-radius:20px;
cursor:pointer;
color:#FFF;
padding: 5px 10px 5px 10px;
text-decoration: none;
text-align:center;
font-weight:bold;
width:55%;
text-shadow: 2px 2px 4px #000;
box-shadow: 1px 1px 2px #000;
border-style:solid;
border-width:1px;
border-color:#F00;
}
.botonredondo:hover{
background-color:#6C0;
background: linear-gradient(#C30, #F60);
color:#FC0;
}
<form name="frmcontacto" id="frmcontacto" method="post" action="enviar_mailreserva.php">
<table>
<tr>
<td colspan="6">
<input type="text" input name="txtnomtour" id="txtnomtour" disabled="disabled" style="background-color:transparent; border:hidden; font-size:30px;"/>
</td>
</tr>
<tr>
<td colspan="2">
<font face="Arial, Helvetica, sans-serif" size="3" color="#333">Fecha del tour:</font>
</td>
<td colspan="2">
<input type="text" name="txtfecha" id="txtfecha" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; padding-left:10px; padding-right:10px;"/>
</td>
</tr>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif" size="3" color="#333">Adultos</font>
</td>
<td>
<input type="number" name="txtadultos" id="txtadultos" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; width:40px; padding-left:10px; padding-right:10px;" min="2" max="15">
</td>
<td>
<font face="Arial, Helvetica, sans-serif" size="3" color="#333">Niños (Menores de 12 años):</font>
</td>
<td>
<input type="number" name="txtninos" id="txtninos" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; width:40px; padding-left:10px; padding-right:10px;" min="1" max="15">
</td>
<td>
<font face="Arial, Helvetica, sans-serif" size="3" color="#333">Lugar y Hora de salida:</font>
</td>
<td>
<select name="txtpickup" id="txtpickup" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; padding-left:10px; padding-right:10px;">
<option value="1">Hotel Country Inn & Suites Aeropuerto</option>
</select>
</td>
</tr>
<tr>
<td>
Nombre Contacto:
</td>
<td colspan="5">
<input type="text" name="txtnombre" id="txtnombre" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; width:625px; padding-left:10px; padding-right:10px;">
</td>
</tr>
<tr>
<td>
E-Mail:
</td>
<td colspan="5">
<input type="text" name="txtmail" id="txtmail" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; width:625px; padding-left:10px; padding-right:10px;">
</td>
</tr>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif" size="3" color="#333">Teléfono:</font>
</td>
<td>
<input type="text" name="txtareatel" id="txtareatel" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; width:40px; padding-left:10px; padding-right:10px;">
</td>
<td>
<input type="text" name="txtnumtel" id="txtnumtel" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; padding-left:10px; padding-right:10px;">
</td>
<td>
<font face="Arial, Helvetica, sans-serif" size="3" color="#333">Móbil:</font>
</td>
<td>
<input type="text" name="txtareacel" id="txtareacel" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; width:40px; padding-left:10px; padding-right:10px;">
</td>
<td>
<input type="text" name="txtnumcel" id="txtnumcel" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:30px; padding-left:10px; padding-right:10px;">
</td>
</tr>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif" size="3" color="#333">Comentarios:</font>
</td>
<td colspan="5">
<textarea name="txtcoment" id="txtcoment" cols="47" rows="5" style="border:hidden; box-shadow: 0px 1px 2px rgba(0,0,0,0.4); height:100px; width:400px; padding-left:10px; padding:10px 10px 10px 10px;"></textarea>
</td>
<tr>
<td colspan="6">
<p align="center"><input type="submit" name="btnenviar" id="btnenviar" value="Enviar"></p>
</td>
</tr>
</table>
</form>
<!--This is the button-->
<table>
<tr>
<td>
<img src="../images/booking_icon.png" width="20" height="20"></td>
<td valign="middle"><a onclick="showcap('formbooking', 'Aguas Termales Baldí')" class="botonredondo">Reserve Aquí</a></td>
</tr>
</table>
答案 0 :(得分:0)
根据您提供的代码:
id="formbooking"
的元素。因此,我不确定涉及此元素id的js代码的用途是什么。txtnomtour
似乎包含disabled="disabled"
属性。提交表单时,不会发布已禁用的输入字段值。 要实现您所需的行为,您可能需要从disabled="disabled"
输入字段中删除txtnomtour
。
另一方面,代码的一些改进将是替换以下HTML标记:
<a onclick="showcap('formbooking', 'Aguas Termales Baldí')" class="botonredondo">Reserve Aquí</a>
使用正常的提交按钮:
<button type="submit">Reserve Aqui</button>
这将允许通过相同的逻辑流程处理表单。因此,当用户单击按钮或在输入字段上按Enter键时,它将运行javascript。
然后,在您的表单标记中,您可能需要包含以下内容:
<form name="frmcontacto" id="frmcontacto" method="post" action="enviar_mailreserva.php" onsubmit="return showcap('formbooking', 'Aguas Termales Baldí');">
这将导致表单在onsubmit
中运行javascript代码,然后再进行处理。
然后,在您的js文件中,替换以下内容:
function showcap(nom,tour) {
// what this is for?
var nombretour1 = tour;
var div = document.getElementById(nom);
div.style.display = "block";
// this will update the txtnomtour value
document.getElementById('txtnomtour').value = nombretour1;
return true; // this basically tells the form to continue to submit
}