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

                    Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                    Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                    How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page