doujianjian2060 2014-10-23 20:07
浏览 22
已采纳

表单不提交动作= PHP

so... I have a form in a html page who, in submit, will call teste1.php who will add the form fieds to a mysql db. The problem is the form never submit. I have two forms on this page (yes, I need both), but I don't think thats the problem.

Ok, so, this is my form:

<div id="apresentacao">
        <form  method="post" action="teste1.php" id="form" style="display:none">

            <div>
                <label for="nome">Nome:</label>
                <input class="form-control" placeholder="Não obrigatório" autofocus="autofocus" type="text" name="nome" id="nome" />
            </div>

            <div>
                <label for="email">* Email:</label>
                <input class="form-control" pattern="^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$" placeholder="Ex: nome@gmail.com" type="email" name="email" id="email" /> 
            </div>

            <div>
                <label for="enderecoform">Endereço:</label>
                <input type="text" id="enderecoform" name="enderecoform" />
            </div>

            <div>
                <label for="latitude">Latitude</label>
                <input type="text" id="txtLatitude" name="txtLatitude" class="form-control" />
            </div>

            <div>
                <label for="longitude">Longitude</label>
                <input type="text" id="txtLongitude" name="txtLongitude" class="form-control" />
            </div>

            <div>
                <label for="data">Data:</label>
                <input class="form-control" type="text" name="" id="data" />
            </div>

            <div>
                <label for="crime">Crime:</label>
                    <select name="sexo" id="sexo" class="form-control" >
                        <option class="form-control" value="">Selecione...</option>
                        <option class="form-control" value="Assalto">Assalto</option>
                        <option class="form-control" value="Agressao1">Agressão física</option>
                        <option class="form-control" value="Agressao2">Agressão verbal</option>
                        <option class="form-control" value="Estupro">Estupro</option>
                        <option class="form-control" value="Invasão">Invasão à domicílio</option>
                        <option class="form-control" value="Latrocinio">Latrocínio</option>
                        <option class="form-control" value="Homicídio">Homicídio</option>
                        <option class="form-control" value="Furto">Furto</option>
                        <option class="form-control" value="Outros">Outros</option>
                    </select>
            </div>

            <div>
                <label for="textarea">Descrição:</label>
                <textarea maxlength = "150" cols="50" rows="2" class="form-control">
                </textarea>
            </div>

            <br />

            <div>
                <input type="reset" id="limpar" class="btn btn-info" name="limpar" value="Limpar" />
            </div>

            <div>
                <input type="submit" id="inserir" class="btn btn-success" name="inserir" value="Cadastrar" />
            </div>

        </form>
    </div>

And this is my php file:

<?php

$endereco = $_REQUEST['enderecoform'];
$latitude = $_REQUEST['txtLatitude'] ;
$longitude = $_REQUEST['txtLongitude'];
//inserir(array("latitude","longitude"), array("1","1"), "crimes");

echo "$endereco";
echo "$latitude";
echo "$longitude";

?>

EDIT

When I click in the submit button, nothing happens, it just stays on the same page, like that button had no action at all. Also, the form is set to "hidden" cause at first, i didn't want to show it, but there are two buttons on the page, one wich sets it to "block" and the other to "hidden", so the user decide's it.

  • 写回答

2条回答 默认 最新

  • douti9253 2014-10-23 20:35
    关注

    hi i think two forms is not really matter fact. but it's better to prevent to do this.

    i guess that you can solve your problem by using jquery command.

    1. add jQuery library into your source.
    2. change your submit button type to button
    3. add this attribute into your button code: onclick="javascript:$('#form').submit();"

    i think this could solve your problem. for make sure if your form work fine you can add this attribute into your form code: onsubmit="return true;"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿