javascript - How to update 2 forms with one submit button -
i have 2 forms on page i'm looking update 1 submit button.
i able update each form individually, however, haven't been able update them concurrently using same button.
the first form updated via php code located on same page (say page1.php) i'm putting button.
the second form updated via redirection page (let's page2.php) event called/handled (after completion, page redirects page1.php changes can viewed) , achieve using onclick="page2.php".
i wondering how should go getting both of these forms update when click button.
code example:
<form id="form" method="post" action="page1.php"> <input type="submit" class="button" value="submit" onclick="form.action=\'page2.php\';" /> </form>
assuming updating form, mean submitting, there no way can submit 2 forms @ once since can't have 2 redirections @ same time (it won't make sense).
but, 1 of options submit first form via ajax call, , if response correct, normal submit of other form. makes sense since said you're submitting first form current page you're on, means no layout changes, etc...
ideally, you'd make new landing page ajax call (no need render whole page behind curtains) output result of whatever you're doing there (for example, updating database, , if success, echo 'ok'). check if response expected 1 ('ok' in case above, though might want return more info, id or something), , if so, submit second form regularly.
hope wasn't confusing.
the other method can suggest simpler, involves changing app flow.
you can try combine 2 forms single form , submit page2. it's worth thinking about, altough might require lot of rewriting of existing code.
Comments
Post a Comment