java - How to design an extendable HTML form without JavaScript? -
designing , processing form user can add arbitrary number of new input fields tedious without using javascript.
currently doing following: using two different submit buttons in form, 1 adding new input field , 1 submitting form results database request.
the used method post
for adding new input fields use get since 2 methods in 1 form not possible have in post request.
making 1 type of input field rather easy, when need sub-forms (some groups of input fields in same form), becomes not tedious, error-prone!
i not satisfied, there more intelligent way realize without starting write lot of processing code , doing redirection or @ least ease implementation reduce error risk!
also, maybe there solution provided java solve generically elegant, since using java servlets.
with javascript turned on offer separate solution, concerned fall solution, not normal case.
see, working without javascript severely restrict abilities: have rely upon standard http request/response cycle. in other words, have rebuild new page (adding input field) , send new page each time - there's no workarounds.
here's how implement it:
<form action="/path/to/action" method="post"> <input name="param_a" /> <input name="param_b" /> <button type="submit" name="next_input" value="param_c">add field</button> <button type="submit" name="submit">submit form</button> </form> ... within server-side code i'd check whether next_input param sent or not. if sent, value used control added - , give corresponding value (param_d, example) next next_input.
update: can't wondering necessary. design 'no js' cases when these pages typical landing pages (scanned search robots). thinking users go page without js enabled, yet willing use pretty things enabled... well, it's not cost-effective, least. )
Comments
Post a Comment