Flutter_widget_from_html: Is form tag supported?

Created on 10 Jan 2020  路  8Comments  路  Source: daohoangson/flutter_widget_from_html

I want to use form html tag and the submit button should open the URL in in-appbrowser. But the submit button is not visible. For example:

HtmlWidget("""
<form action='http://www.someurl.com' method='post' target='_blank'>
         <input name='fname' value='s1' type='hidden'><br>
         <input name='lname' value='s2' type='hidden'><br>
         <input type='submit' value='Submit'>
 </form>""",  webView: true)

Could you please tell me if it should work or not?

question

Most helpful comment

The official webview_flutter currently doesn't allow you to send a POST as the initial request so you will have to use the community plugin or implement "hack" to achieve this. If your form doesn't have any other inputs except a submit button, you can try this sample code. Please note that it won't work properly if your form has a text input or similar.

https://gist.github.com/daohoangson/57d950dffb1723b47df13cc85e0ecdc3

The form in this example is:

<form action="https://postman-echo.com/post" method="POST">
  <input type="hidden" name="foo" value="bar" />
  <input type="submit" value="Submit">
</form>

Click the button will open a new screen and submit the form automatically, check out this video:

https://youtu.be/iWZ1jtRCUUU

All 8 comments

Form elements (FORM, INPUT tags etc.) will be processed as normal tag but they won't work. This is the expected behavior for now. There was some discussion about this in #1 but there is no plan to implement yet.

Could you please tell me if there is any way by which I can achieve this. I have tried with so many plugins. I have explained it here.

Have you considered using a WebView for your form?

Yes. But it does not handle the redirection of form in full page webview/in-app-browser.

I think your best bet is to render the form in a full in app webview and let user interact with the form then submit it from there.

Only a button will be visible to user. That webview with the button will be small (in a card of list) but the redirection after form submission should be on full screen webview. I am facing issue in that. Or is there any way by which I can capture the response of form submission and open it in full page webview?

The official webview_flutter currently doesn't allow you to send a POST as the initial request so you will have to use the community plugin or implement "hack" to achieve this. If your form doesn't have any other inputs except a submit button, you can try this sample code. Please note that it won't work properly if your form has a text input or similar.

https://gist.github.com/daohoangson/57d950dffb1723b47df13cc85e0ecdc3

The form in this example is:

<form action="https://postman-echo.com/post" method="POST">
  <input type="hidden" name="foo" value="bar" />
  <input type="submit" value="Submit">
</form>

Click the button will open a new screen and submit the form automatically, check out this video:

https://youtu.be/iWZ1jtRCUUU

Thank you so much for taking the time and effort in writing this. I really appreciate that. It worked as expected :)

Was this page helpful?
0 / 5 - 0 ratings