(a quick disclaimer that I don't think you need to know much about Node
or Express
to answer this question! It's very much an issue on the jQuery form submission's end)
I have a form set up on Wordpress, whose data I want to send to my Node.js
process. The node process is located at http://localhost:5000/agm/saveNewUser
and accepts POST
commands, which I've verified is working. The Node server sits on top of Express
.
I'm having trouble getting the data from my front-end form to Node. The form looks like this:
<form class="form-horizontal classy-form franklin-book ng-pristine ng-valid" id="signup" role="form">
<div class="form-group">
<label class="col-md-2 control-label" for="inputName">
Name </label>
<div class="col-md-10">
<input class="form-control" id="inputName" type="text" mouseev="true" keyev="true">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="inputEmail">
Email
</label>
<div class="col-md-10">
<input class="form-control" id="inputEmail" type="email">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="inputLocation">
Location
</label>
<p>
</p>
<div class="col-md-10">
<input class="form-control" id="inputLocation" type="text">
</div>
</div>
<div class="radio">
<label><input id="optionsRadios1" type="radio" checked="checked" name="optionsRadios" value="option1">Start the course from Monday</label>
</div>
<div class="radio">
<label><input id="optionsRadios2" type="radio" name="optionsRadios" value="option2">Start the course from today</label>
</div>
<div class="form-group">
<div class="col-md-10">
<button id="formSubmit" class="btn btn-default" type="submit"><br>
Get in contact</button>
</div>
</div>
</form>
The form submits like so, using the jQuery Form Plugin
:
$('#signup').ajaxForm({
url: 'http://localhost:5000/agm/saveNewUser/',
type: 'post'
})
My Node server is simply set up as:
exports.saveNewUser = function (req, res) {
console.log("Saving a new user");
console.log(req);
console.log(res);
// These console.logs are just to debug so I can see if the form data is being posted correctly
};
At present, my Node
console logs a whole bunch of stuff but nothing to do with the actual input from the form. I've tried:
$('#signup').ajaxForm({url: 'http://localhost:5000/agm/saveNewUser/', type: 'post', data: $('#signup').serialize()})
But this results in the form not hitting my node
server at all.