javascript Formulario para correos

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Formulario para correos相关的知识,希望对你有一定的参考价值。

<form id="jquery_form">
    <input type="text" name="subject" placeholder="Subject" />
    <textarea name="text" placeholder="Message" ></textarea>
    <input type="submit" name="send" value="Send" />

    <!-- not required, but we'd appreciate it if you'd link to us somewhere on your site -->
    <p>Powered by <a href="https://postmail.invotes.com" target="_blank">PostMail</a></p>
</form>

<script>

    //update this with your $form selector
    var form_id = "jquery_form";

    var data = {
        "access_token": "xffb9cgbqiyxd8oj64h6688e"
    };

    function onSuccess() {
        // remove this to avoid redirect
        window.location = window.location.pathname + "?message=Email+Successfully+Sent%21&isError=0";
    }

    function onError(error) {
        // remove this to avoid redirect
        window.location = window.location.pathname + "?message=Email+could+not+be+sent.&isError=1";
    }

    var sendButton = $("#" + form_id + " [name='send']");

    function send() {
        sendButton.val('Sending…');
        sendButton.prop('disabled',true);

        var subject = $("#" + form_id + " [name='subject']").val();
        var message = $("#" + form_id + " [name='text']").val();
        data['subject'] = subject;
        data['text'] = message;

        $.post('https://postmail.invotes.com/send',
            data,
            onSuccess
        ).fail(onError);

        return false;
    }

    sendButton.on('click', send);

    var $form = $("#" + form_id);
    $form.submit(function( event ) {
        event.preventDefault();
    });
</script>
    
    
<form action="https://postmail.invotes.com/send"
    method="post" id="email_form">

    <input type="text" name="subject" placeholder="Subject" />
    <textarea name="text" placeholder="Message"></textarea>
    <input type="hidden" name="access_token" value="xffb9cgbqiyxd8oj64h6688e" />
      <!-- return urls can be fully qualified -OR-
         start with / for root relative -OR-
         start with . for url relative --> 
    <input type="hidden" name="success_url" value=".?message=Email+Successfully+Sent%21&isError=0" />
    <input type="hidden" name="error_url" value=".?message=Email+could+not+be+sent.&isError=1" />
   

    <!-- set the reply-to address -->
    <!-- <input type="text" name="reply_to"
                placeholder="Your Email" /> -->

    <!-- to append extra fields, use the extra_ prefix.
        Entries will be appended to your message body. -->
    <!-- <input type="text" name="extra_phone_number"
                placeholder="Phone Number" /> -->

    <!-- to split your message into 160 chars
         for an sms gateway -->
    <!-- <input type="hidden"
                name="sms_format" value="true" /> -->
   
    <input id="submit_form" type="submit" value="Send" />
    <!-- not required, but we'd appreciate it if you'd link to us somewhere on your site -->
    <p>Powered by <a href="https://postmail.invotes.com" target="_blank">PostMail</a></p>
</form>
     
<!-- optional, prevents the submit button from being pressed more than once -->
<script>
    var submitButton = document.getElementById("submit_form");
    var form = document.getElementById("email_form");
    form.addEventListener("submit", function (e) {
        setTimeout(function() {
            submitButton.value = "Sending...";
            submitButton.disabled = true;
        }, 1);
    });
</script> 


<form id="javascript_form">
    <input type="text" name="subject" placeholder="Subject" />
    <textarea name="text" placeholder="Message"></textarea>
    <input type="submit" id="js_send" value="Send" />

    <!-- not required, but we'd appreciate it if you'd link to us somewhere on your site -->
    <p>Powered by <a href="https://postmail.invotes.com" target="_blank">PostMail</a></p>
</form>

<script>

    //update this with your js_form selector
    var form_id_js = "javascript_form";

    var data_js = {
        "access_token": "xffb9cgbqiyxd8oj64h6688e"
    };

    function js_onSuccess() {
        // remove this to avoid redirect
        window.location = window.location.pathname + "?message=Email+Successfully+Sent%21&isError=0";
    }

    function js_onError(error) {
        // remove this to avoid redirect
        window.location = window.location.pathname + "?message=Email+could+not+be+sent.&isError=1";
    }

    var sendButton = document.getElementById("js_send");

    function js_send() {
        sendButton.value='Sending…';
        sendButton.disabled=true;
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
            if (request.readyState == 4 && request.status == 200) {
                js_onSuccess();
            } else
            if(request.readyState == 4) {
                js_onError(request.response);
            }
        };

        var subject = document.querySelector("#" + form_id_js + " [name='subject']").value;
        var message = document.querySelector("#" + form_id_js + " [name='text']").value;
        data_js['subject'] = subject;
        data_js['text'] = message;
        var params = toParams(data_js);

        request.open("POST", "https://postmail.invotes.com/send", true);
        request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        request.send(params);

        return false;
    }

    sendButton.onclick = js_send;

    function toParams(data_js) {
        var form_data = [];
        for ( var key in data_js ) {
            form_data.push(encodeURIComponent(key) + "=" + encodeURIComponent(data_js[key]));
        }

        return form_data.join("&");
    }

    var js_form = document.getElementById(form_id_js);
    js_form.addEventListener("submit", function (e) {
        e.preventDefault();
    });
</script>

以上是关于javascript Formulario para correos的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript 提交un formulario hacia un popup

JavaScript Utilizar la tecla intro como un tabulador de formulario

Procesar formulario desde facebook粉丝页面

text Formulario输入

html Formulario de contacto

css Formulario de contacto desplegable。