Send more data than only the form (node.js post)2019 Community Moderator ElectionJavaScript post request like a form submitTrigger a button click with JavaScript on the Enter key in a text boxHow can I upload files asynchronously?Obtain form input fields using jQuery?How can I convert a string to boolean in JavaScript?Convert form data to JavaScript object with jQueryjQuery AJAX submit formapplication/x-www-form-urlencoded or multipart/form-data?jQuery Ajax POST example with PHPHow is an HTTP POST request made in node.js?

Vocabulary for giving just numbers, not a full answer

What is the magic ball of every day?

Bash script should only kill those instances of another script's that it has launched

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

Single word request: Harming the benefactor

Hotkey (or other quick way) to insert a keyframe for only one component of a vector-valued property?

How to write ı (i without dot) character in pgf-pie

Should I take out a loan for a friend to invest on my behalf?

Plausibility of Mushroom Buildings

Does a warlock using the Darkness/Devil's Sight combo still have advantage on ranged attacks against a target outside the Darkness?

How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?

Why would one plane in this picture not have gear down yet?

Why does Captain Marvel assume the people on this planet know this?

Filtering SOQL results with optional conditionals

How does NOW work?

Reversed Sudoku

weren't playing vs didn't play

Does this video of collapsing warehouse shelves show a real incident?

NASA's RS-25 Engines shut down time

Is "history" a male-biased word ("his+story")?

How does one describe somebody who is bi-racial?

Find longest word in a string: are any of these algorithms good?

They call me Inspector Morse

Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?



Send more data than only the form (node.js post)



2019 Community Moderator ElectionJavaScript post request like a form submitTrigger a button click with JavaScript on the Enter key in a text boxHow can I upload files asynchronously?Obtain form input fields using jQuery?How can I convert a string to boolean in JavaScript?Convert form data to JavaScript object with jQueryjQuery AJAX submit formapplication/x-www-form-urlencoded or multipart/form-data?jQuery Ajax POST example with PHPHow is an HTTP POST request made in node.js?










0















Is it possible when someone submits a form it sends additional things instead of only the input fields? In my case it would be the username.










share|improve this question


























    0















    Is it possible when someone submits a form it sends additional things instead of only the input fields? In my case it would be the username.










    share|improve this question
























      0












      0








      0








      Is it possible when someone submits a form it sends additional things instead of only the input fields? In my case it would be the username.










      share|improve this question














      Is it possible when someone submits a form it sends additional things instead of only the input fields? In my case it would be the username.







      javascript node.js forms post webforms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 5:57









      SW30000SW30000

      52




      52






















          2 Answers
          2






          active

          oldest

          votes


















          0














          As @jayarjo as said, you can intercept the form submission and handle it manually, for example you can use Ajax as follows.



          Note:; To use Ajax make sure you add its script for example



          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>



          <script>


          $('#newform').on('submit', function (event)
          event.preventDefault();
          var data =
          username: $('#username').val(),
          ;

          $.ajax(
          url: '/upload',
          data: data,
          method: 'POST'
          ).then(function (response)

          $('body').append(response);
          ).catch(function (err)
          console.error(err);
          );
          );
          </script>



          Hope this helps.






          share|improve this answer






























            1














            You can always intercept the submission of the form and handle it manually. In fact that's what you should do anyway if you want to validate the form fields beforehand.



            The logic is pretty straightforward. You attach an onsubmit event listener to the form. Prevent the auto submission by calling preventDefault() on the event. Then collect the values from all the fields, do the validation (if email is in the proper format, if passwords match, etc.), add arbitrary accompanying properties to the object and post the whole thing to the server via ajax post request.



            Since you are asking that kind of question I will recommend to use some JS library to make it easier, jQuery is perfect for such case:






            $('#myForm').on('submit', function(e) 
            e.preventDefault();

            const $form = $(this);
            const method = $form.attr('method');
            const action = $form.attr('action')
            const fields = $form.serializeArray();

            fields.push(
            name: 'username',
            value: 'myUsername'
            )

            const queryStr = $.param(fields);

            $[method](action, queryStr)
            .done(function()
            // submission was successful - do something, refresh page for exmaple
            )
            .fail(function()
            // submission failed
            );
            );

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

            <form id="myForm" method="post" action="/handle.php">
            My name is: <input type="text" name="fname" /><br />
            <label for="agree">I agree</label> <input type="checkbox" name="agree" value="1" /><br />
            <button type="submit">Submit</button>
            </form>





            Of course /handle.php is a fake endpoint so submission here obviously won't work.






            share|improve this answer

























            • How does this code look like?

              – SW30000
              Mar 7 at 6:00










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036982%2fsend-more-data-than-only-the-form-node-js-post%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            As @jayarjo as said, you can intercept the form submission and handle it manually, for example you can use Ajax as follows.



            Note:; To use Ajax make sure you add its script for example



            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>



            <script>


            $('#newform').on('submit', function (event)
            event.preventDefault();
            var data =
            username: $('#username').val(),
            ;

            $.ajax(
            url: '/upload',
            data: data,
            method: 'POST'
            ).then(function (response)

            $('body').append(response);
            ).catch(function (err)
            console.error(err);
            );
            );
            </script>



            Hope this helps.






            share|improve this answer



























              0














              As @jayarjo as said, you can intercept the form submission and handle it manually, for example you can use Ajax as follows.



              Note:; To use Ajax make sure you add its script for example



              <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>



              <script>


              $('#newform').on('submit', function (event)
              event.preventDefault();
              var data =
              username: $('#username').val(),
              ;

              $.ajax(
              url: '/upload',
              data: data,
              method: 'POST'
              ).then(function (response)

              $('body').append(response);
              ).catch(function (err)
              console.error(err);
              );
              );
              </script>



              Hope this helps.






              share|improve this answer

























                0












                0








                0







                As @jayarjo as said, you can intercept the form submission and handle it manually, for example you can use Ajax as follows.



                Note:; To use Ajax make sure you add its script for example



                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>



                <script>


                $('#newform').on('submit', function (event)
                event.preventDefault();
                var data =
                username: $('#username').val(),
                ;

                $.ajax(
                url: '/upload',
                data: data,
                method: 'POST'
                ).then(function (response)

                $('body').append(response);
                ).catch(function (err)
                console.error(err);
                );
                );
                </script>



                Hope this helps.






                share|improve this answer













                As @jayarjo as said, you can intercept the form submission and handle it manually, for example you can use Ajax as follows.



                Note:; To use Ajax make sure you add its script for example



                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>



                <script>


                $('#newform').on('submit', function (event)
                event.preventDefault();
                var data =
                username: $('#username').val(),
                ;

                $.ajax(
                url: '/upload',
                data: data,
                method: 'POST'
                ).then(function (response)

                $('body').append(response);
                ).catch(function (err)
                console.error(err);
                );
                );
                </script>



                Hope this helps.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 6:12









                Ike MawiraIke Mawira

                4818




                4818























                    1














                    You can always intercept the submission of the form and handle it manually. In fact that's what you should do anyway if you want to validate the form fields beforehand.



                    The logic is pretty straightforward. You attach an onsubmit event listener to the form. Prevent the auto submission by calling preventDefault() on the event. Then collect the values from all the fields, do the validation (if email is in the proper format, if passwords match, etc.), add arbitrary accompanying properties to the object and post the whole thing to the server via ajax post request.



                    Since you are asking that kind of question I will recommend to use some JS library to make it easier, jQuery is perfect for such case:






                    $('#myForm').on('submit', function(e) 
                    e.preventDefault();

                    const $form = $(this);
                    const method = $form.attr('method');
                    const action = $form.attr('action')
                    const fields = $form.serializeArray();

                    fields.push(
                    name: 'username',
                    value: 'myUsername'
                    )

                    const queryStr = $.param(fields);

                    $[method](action, queryStr)
                    .done(function()
                    // submission was successful - do something, refresh page for exmaple
                    )
                    .fail(function()
                    // submission failed
                    );
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

                    <form id="myForm" method="post" action="/handle.php">
                    My name is: <input type="text" name="fname" /><br />
                    <label for="agree">I agree</label> <input type="checkbox" name="agree" value="1" /><br />
                    <button type="submit">Submit</button>
                    </form>





                    Of course /handle.php is a fake endpoint so submission here obviously won't work.






                    share|improve this answer

























                    • How does this code look like?

                      – SW30000
                      Mar 7 at 6:00















                    1














                    You can always intercept the submission of the form and handle it manually. In fact that's what you should do anyway if you want to validate the form fields beforehand.



                    The logic is pretty straightforward. You attach an onsubmit event listener to the form. Prevent the auto submission by calling preventDefault() on the event. Then collect the values from all the fields, do the validation (if email is in the proper format, if passwords match, etc.), add arbitrary accompanying properties to the object and post the whole thing to the server via ajax post request.



                    Since you are asking that kind of question I will recommend to use some JS library to make it easier, jQuery is perfect for such case:






                    $('#myForm').on('submit', function(e) 
                    e.preventDefault();

                    const $form = $(this);
                    const method = $form.attr('method');
                    const action = $form.attr('action')
                    const fields = $form.serializeArray();

                    fields.push(
                    name: 'username',
                    value: 'myUsername'
                    )

                    const queryStr = $.param(fields);

                    $[method](action, queryStr)
                    .done(function()
                    // submission was successful - do something, refresh page for exmaple
                    )
                    .fail(function()
                    // submission failed
                    );
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

                    <form id="myForm" method="post" action="/handle.php">
                    My name is: <input type="text" name="fname" /><br />
                    <label for="agree">I agree</label> <input type="checkbox" name="agree" value="1" /><br />
                    <button type="submit">Submit</button>
                    </form>





                    Of course /handle.php is a fake endpoint so submission here obviously won't work.






                    share|improve this answer

























                    • How does this code look like?

                      – SW30000
                      Mar 7 at 6:00













                    1












                    1








                    1







                    You can always intercept the submission of the form and handle it manually. In fact that's what you should do anyway if you want to validate the form fields beforehand.



                    The logic is pretty straightforward. You attach an onsubmit event listener to the form. Prevent the auto submission by calling preventDefault() on the event. Then collect the values from all the fields, do the validation (if email is in the proper format, if passwords match, etc.), add arbitrary accompanying properties to the object and post the whole thing to the server via ajax post request.



                    Since you are asking that kind of question I will recommend to use some JS library to make it easier, jQuery is perfect for such case:






                    $('#myForm').on('submit', function(e) 
                    e.preventDefault();

                    const $form = $(this);
                    const method = $form.attr('method');
                    const action = $form.attr('action')
                    const fields = $form.serializeArray();

                    fields.push(
                    name: 'username',
                    value: 'myUsername'
                    )

                    const queryStr = $.param(fields);

                    $[method](action, queryStr)
                    .done(function()
                    // submission was successful - do something, refresh page for exmaple
                    )
                    .fail(function()
                    // submission failed
                    );
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

                    <form id="myForm" method="post" action="/handle.php">
                    My name is: <input type="text" name="fname" /><br />
                    <label for="agree">I agree</label> <input type="checkbox" name="agree" value="1" /><br />
                    <button type="submit">Submit</button>
                    </form>





                    Of course /handle.php is a fake endpoint so submission here obviously won't work.






                    share|improve this answer















                    You can always intercept the submission of the form and handle it manually. In fact that's what you should do anyway if you want to validate the form fields beforehand.



                    The logic is pretty straightforward. You attach an onsubmit event listener to the form. Prevent the auto submission by calling preventDefault() on the event. Then collect the values from all the fields, do the validation (if email is in the proper format, if passwords match, etc.), add arbitrary accompanying properties to the object and post the whole thing to the server via ajax post request.



                    Since you are asking that kind of question I will recommend to use some JS library to make it easier, jQuery is perfect for such case:






                    $('#myForm').on('submit', function(e) 
                    e.preventDefault();

                    const $form = $(this);
                    const method = $form.attr('method');
                    const action = $form.attr('action')
                    const fields = $form.serializeArray();

                    fields.push(
                    name: 'username',
                    value: 'myUsername'
                    )

                    const queryStr = $.param(fields);

                    $[method](action, queryStr)
                    .done(function()
                    // submission was successful - do something, refresh page for exmaple
                    )
                    .fail(function()
                    // submission failed
                    );
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

                    <form id="myForm" method="post" action="/handle.php">
                    My name is: <input type="text" name="fname" /><br />
                    <label for="agree">I agree</label> <input type="checkbox" name="agree" value="1" /><br />
                    <button type="submit">Submit</button>
                    </form>





                    Of course /handle.php is a fake endpoint so submission here obviously won't work.






                    $('#myForm').on('submit', function(e) 
                    e.preventDefault();

                    const $form = $(this);
                    const method = $form.attr('method');
                    const action = $form.attr('action')
                    const fields = $form.serializeArray();

                    fields.push(
                    name: 'username',
                    value: 'myUsername'
                    )

                    const queryStr = $.param(fields);

                    $[method](action, queryStr)
                    .done(function()
                    // submission was successful - do something, refresh page for exmaple
                    )
                    .fail(function()
                    // submission failed
                    );
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

                    <form id="myForm" method="post" action="/handle.php">
                    My name is: <input type="text" name="fname" /><br />
                    <label for="agree">I agree</label> <input type="checkbox" name="agree" value="1" /><br />
                    <button type="submit">Submit</button>
                    </form>





                    $('#myForm').on('submit', function(e) 
                    e.preventDefault();

                    const $form = $(this);
                    const method = $form.attr('method');
                    const action = $form.attr('action')
                    const fields = $form.serializeArray();

                    fields.push(
                    name: 'username',
                    value: 'myUsername'
                    )

                    const queryStr = $.param(fields);

                    $[method](action, queryStr)
                    .done(function()
                    // submission was successful - do something, refresh page for exmaple
                    )
                    .fail(function()
                    // submission failed
                    );
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

                    <form id="myForm" method="post" action="/handle.php">
                    My name is: <input type="text" name="fname" /><br />
                    <label for="agree">I agree</label> <input type="checkbox" name="agree" value="1" /><br />
                    <button type="submit">Submit</button>
                    </form>






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 7 at 6:21

























                    answered Mar 7 at 5:59









                    jayarjojayarjo

                    6,381136397




                    6,381136397












                    • How does this code look like?

                      – SW30000
                      Mar 7 at 6:00

















                    • How does this code look like?

                      – SW30000
                      Mar 7 at 6:00
















                    How does this code look like?

                    – SW30000
                    Mar 7 at 6:00





                    How does this code look like?

                    – SW30000
                    Mar 7 at 6:00

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036982%2fsend-more-data-than-only-the-form-node-js-post%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme