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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用