What I'm trying to accomplish is having an input box called "Order Number" the user can put in an order number and hit submit. When they hit submit, it redirects to another page where fields would get captured based on that order number that was enterered on the previous page for the input box.
What I have figured out so far is:
- passing a post request to the / route which is the page where the input box is on for the user to put in the order number.
- With help, I managed to pass the orderNum in the url on the next page
What I'm stuck on is trying to figure out how to fetch the orderNum that I passed in the URL to the new route on the server. Once I can fetch it I'll know how to set it to state and populate the boxes with the orderNum
Hope that was clear enough
My Attempt:
app.post('/', function(req, res){
request.query("select [TableId] FROM [SACH_QA].[Orders].[Order] where [TableId] ='" + req.body.orderNum + "'", function(error, result){
if(error){
throw error;
} else {
//console.log(result);
res.redirect('/relotoForm');
}
});
});
app.post('/reloToForm', function(err, res){
if(err){
throw err;
} else {
// How can I have access to req.body.orderNum from / on this request?
}
});
View:
onSubmit(e){
if(this.state.orderNum === '') {
this.setState({
errorMsg: 'Please enter an order number.'
});
e.preventDefault();
} else {
this.setState({
errorMsg: ''
});
console.log('passed');
// Submit the form
const reloData = {
orderNum: this.state.orderNum
}
fetch('/', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(reloData)
}).catch(function(err){
console.log(err);
})
}
//e.preventDefault();
}