WebDev Post from page to page example

Could someone provide example code that shows how to do a Post from one WebDev page to another WebDev page?
No matter what combinations I have tried I cannot get it to have the postData accessible.

Basically a form to do a post on the first page, and the second page to get the postData for processing?

Yes, a form should definitely work if you want a user-submitted POST. Are you able to share any HTML you’ve tried so far?

ht = '<form class="navbar-form navbar-left" action="LinkToWebDevPageToProcessPOST" method="POST">'
ht += '<div class="form-group">'
ht += '<label for="sDate" class="sr-only">Start Date</label>'
ht += '<input name="SDate" type="text" placeholder="Start Date" class="datepicker-here" data-language="en" data-date-format="yyyy-mm-dd">'
ht += '<label for="eDate" class="sr-only">End Date</label>'
ht += '<input type="text" name="eDate" placeholder="End Date" class="datepicker-here" data-language="en" data-date-format="yyyy-mm-dd">'
ht += '<button type="submit" class="btn btn-primary">Submit</button>'
ht += '</div>'
ht += '<input type="hidden" name="Plant" value="237">'
ht += '<input type="hidden" name="Line" value="line1">'
ht += '</form>'    
return {'html': '<html><head></head><body>'+jy+'</body></html>'}

Is the most basic attempt I have tried.
Just a form with a POST action to another page.
The other page fails with a key error on the postData

I have a resource named post. doGet is defined as:

	html = """
	<html>
	<head>
	</head>
	<body>
		<form class="navbar-form navbar-left" action="post" method="POST">
			<div class="form-group">
			<label for="sDate" class="sr-only">Start Date</label>
			<input name="SDate" type="text" placeholder="Start Date" class="datepicker-here" data-language="en" data-date-format="yyyy-mm-dd">
			
			<label for="eDate" class="sr-only">End Date</label>
			<input type="text" name="eDate" placeholder="End Date" class="datepicker-here" data-language="en" data-date-format="yyyy-mm-dd">
			
			<button type="submit" class="btn btn-primary">Submit</button>
			</div>
			<input type="hidden" name="Plant" value="237">
			<input type="hidden" name="Line" value="line1">
		</form>
	</body>
	</html>
	"""
	return {'html': html}

doPost is just:

	log = system.util.getLogger("webdev post")
	log.info(str(request["data"]))
	log.info(str(request["headers"]))
	log.info(str(request["params"]))

If I load the page and submit the form, then go into the logs, request["params"] is logged as:
{'Line': u'line1', 'Plant': u'237', 'SDate': u'asdf', 'eDate': u'asdf'}
Maybe your form URL isn’t redirecting properly? Try browser dev tools (the network tab, specifically) to make sure the POST is going to the location you expect it to.

1 Like

You aren’t using the
request['postData']

request["postData"] is deprecated since 2015, but is exactly the same data as request["data"].

In either case, request["params"] is the actual key you want to access the form data.