Send HTML form without the Submit button

Asked

Viewed 24,064 times

5

It is possible to create a form HTML to automatically upload data from form? Ex: I have one form only with radiobutton and for aesthetic reason I do not want to put the send button, it would be possible to create this?

  • 2

    Yes, by javascript you can do this.

  • I understand, is that this form will be sent in marketing emails and javascript is highly vulnerable to turn email into spam... no way, I will have to put the Ubmit button. Thank you!

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

4 answers

9

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>

It is also possible to use more advanced techniques such as AJAX and/or use libraries that help, such as jQuery.

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

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

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

I put in the Github for future reference.

  • But then I can’t use in email marketing, it’s risky to go straight to the spam box

  • 2

    You shouldn’t even use it to do e-mail marketing. But even if you do, there must be a good reason for this to be considered spam, then it seems that it is best that you do not do things that are considered wrong. Anything wrong that you do may be considered spam by some anti-spam, even some things right. What I realize is that you want to send data without someone’s consent and it’s not the presence of the submit which causes something to be classified as spam, is to do things. It has how to solve your problem but I will not teach because it is wrong, is misleading.

  • I understood, but it is not compromising data, I have solved the problem here. Thank you!

  • 2

    Any data of someone, even if it is an "x" any sent without him knowing that it is being sent is something wrong and ultimately can even be considered illegal and generate a process.

8

Send 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 like another. Even easier is changing a label of a button or input that allows you to do Submit without actually having to have the button/input visible.

Example: http://jsfiddle.net/b9wnw9c6/

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;
}
  • 1

    Good idea. Thank you!

2

I think that’s what I wanted, also I want something like

You need to listen to 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 call Ajax (which could have been a $ .post ()) is necessary as you cannot submit the actual form because it does not prevent un -active element to be sent.

iEnviar form in only 1 input

  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - From Review

  • All right I put what I found here, I have only basic knowledge about it, but the boy’s reasoning seems logical to me

  • The answer is partially in English. Translate it to fit the site.

1

Javascript-enabled:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.