Send form HTML without submit button

4

Is it possible to create an form HTML that automatically sends the form data? Ex: I have a form only with radiobutton and because of aesthetics I do not want to put the submit button, could it be created?

    
asked by anonymous 20.01.2015 / 19:50

4 answers

7

It is possible with JavaScript. Quite simply:

<form name="formulario" action="form.php">
    Digite algo: <input type="text" name="campo">
    <a href="javascript: submitform()">Envie</a>
</form>
<script type="text/javascript">
    function submitform() {
        document.formulario.submit();
    }
</script>

You can also use more advanced techniques such as AJAX and / or use libraries that help with this, such as jQuery .

But your additional comment indicates that you are using the wrong tool for what you want.

See one of the forms by jQuery using .post() :

$.post( "test.php", { name: "John", time: "2pm" })
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  });
    
20.01.2015 / 19:58
7

Submitting a form automatically needs javascript. But there are ways to get around more or less efficient.

If the question is aesthetic it is worth remembering that a button can be easily changed to look different. It's even easier to change a label of a button or input that allows you to submit without actually having button / input visible.

Example: link

Example code:

HTML

<form action="teste.php">
    <label for="enviar">Carregue aqui para enviar</label>
    <input type="submit" id="enviar" />
</form>

CSS

label {
    padding: 20px;
    background-color: #cff;
}
input[type=submit] {
    visibility: hidden;
}
    
20.01.2015 / 20:05
1

I think this is what I wanted, I also want something like this

You need to hear the event launched by your form and process your form before submitting it.

You can follow this example to perform this task:

$(function() {
$("form").submit(function(event) {
    event.preventDefault(); // prevent sending the form before we processed the form

    var active_input        =   $(".active")[0];        
    var active_input_value  =   active_input.val();

    $.ajax({
            url     :   "php_file_to_call.php"
        ,   method  :   "post"
        ,   data    :   { something : active_input_value }
    });
});

});

The Ajax call (which could have been a $ .post ()) is required because you can not send the actual form because it does not prevent an -active element being sent.

Send form in only 1 input

    
13.02.2016 / 02:36
1

With javascript:

var form = new FormData();
form.append('post1', document.getElementById('radiobutton1').value);
form.append('post2', document.getElementById('radiobutton2').value);
form.append('postN', document.getElementById('radiobuttonN').value);
var request = new XMLHttpRequest();
request.open('post', 'arquivo.php');
request.send(form);
    
13.02.2016 / 14:35