Reputation: 1490
I am using Express for API development, Needs to submit HTML form on calling GET API call
I have added below code, it's working fine when its opened from the browser but when calling from Postman or Angular HTTP GET it will not submit a form.
controller code :
zohoFormSubmit: async (req, res, next) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<html><body><meta http-equiv="content-type" content="text/html;charset=UTF-8"><form name="WebToLeads25788000000071001" method="POST" accept-charset="UTF-8" id="zohoForm" action="https://**.zoho.in/crm/**"><input type="text" name="****" value="**" /><input type="hidden" name="zc_gad" id="zc_gad" value="" /><input type="text" name="xmIwtLD" value="**" /><input type="text" name="actionType" value="TGVhZHM=" /><input type="text" name="returnURL" value="https://login.sthalmatrimony.com/" /><input type="text" name="First Name" value="MANGESH" /><input type="text" name="Last Name" value="MANGESH" /><input type="text" name="Email" value="**@gmail.com" /><input type="text" name="Mobile" value="*****" /><input type="text" name="City" value="Pune" /></form><script type="text/javascript">document.WebToLeads25788000000071001.submit();</script></body></html>');
res.end();
}
If any one came across the same scenerio please help here. Thanks
Upvotes: 0
Views: 677
Reputation: 579
please try this code
zohoFormSubmit: async (req, res, next) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<html> <body><meta http-equiv="content-type" content="text/html;charset=UTF-8"><form name="WebToLeads25788000000071001" id="WebToLeads25788000000071001" method="POST" accept-charset="UTF-8" action="https://**.zoho.in/crm/**"><input type="text" name="****" value="**" /><input type="hidden" name="zc_gad" id="zc_gad" value="" /><input type="text" name="xmIwtLD" value="**" /><input type="text" name="actionType" value="TGVhZHM=" /><input type="text" name="returnURL" value="https://login.sthalmatrimony.com/" /><input type="text" name="First Name" value="MANGESH" /><input type="text" name="Last Name" value="MANGESH" /><input type="text" name="Email" value="**@gmail.com" /><input type="text" name="Mobile" value="*****" /><input type="text" name="City" value="Pune" /></form><script type="text/javascript">document.forms[\'WebToLeads25788000000071001\'].submit();</script></body></html>');
res.end();
}
Hope its help
Upvotes: 0
Reputation: 72
You can use res.send("<>HTML here</>")
or res.sendFile(<fileName>)
see: https://expressjs.com/pt-br/api.html#res.send
Upvotes: 1