-1

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.

diogoguidotte
  • 15
  • 1
  • 5

2 Answers2

0

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;"

  • it didn't work this way, but thanks to you I tried "onclick="javascript:document.getElementById('form').submit();"" and it worked! thank you so much – diogoguidotte Oct 23 '14 at 20:53
-1

I don't think there is a way to submit two separate forms with a single submit button.

You would need to use some javascript to get the content of the other form.

Also try to use $_POST instead of $_REQUEST variable

Also make sure teste1.php is in the same folder as your html file

diokey
  • 176
  • 1
  • 2
  • 12
  • The first form has its own submit button, and it works just fine. The problem is with this form. When I click on the submit button, nothing happens, it stays on the page, like that button is invalid or something – diogoguidotte Oct 23 '14 at 20:29
  • Why do you have style="display:none" on the form? do you really wanna hide it? – diokey Oct 23 '14 at 20:33
  • yep, at first. but in the rest of the code there are two buttons who sets it to "block" or "hidden" again, so the user will decide – diogoguidotte Oct 23 '14 at 20:36
  • May be there is something wrong somewhere else in your code,but i just tested your piece of code in jsfiddle and it seems to work. check this out http://jsfiddle.net/fkxbbuwg/ – diokey Oct 23 '14 at 20:46