www.webdeveloper.com
Results 1 to 3 of 3

Thread: Submitting two forms.

  1. #1
    Join Date
    Jan 2014
    Posts
    7

    Submitting two forms.

    Hi.

    I have a html file with a form system two process orders.

    The first form ("form") collects the personal data of the customer and submits it to an email address for me to know her/his identity and contact details so as to reply or deliver the items.

    The second one ("form-order"), immediately after the first form in the code, collects the operation and total information to redirect it to a php file that processes it to the bank.

    The first form displays a series of required fields that must be filled to allow the processing of it and the second form.

    No processing of operation information without a previous sending of personal information to the email address.

    The code is as following:

    Code:
     <form name="form" action="http://cgi.the web site.com/FormMail.pl" method="post">
            <input type="hidden" value="968" name="order"/> 
            <input type="hidden" name="redirect"/> 
            <input type="hidden" value="online@the web site. com" name="recipient"/> 
            <input type="hidden" value="Purchase" name="subject"/> 
            <input name="required" type="hidden" value="Name,Address, E-Mail"/>
              <h2>Personal Identification</h2>
                <div id="fa"><p>Full Name<input name="Name" type="text" id="Name"/></p></div>
            </div>
           <div id="fa">
              <h2>Contact Details</h2>
                <div id="fab"><p>Address<input name="Address" type="text" id="Address"/></p></div>
                <div id="fac"><p>E-Mail<input name="E-Mail" type="text" id="E-Mail"/></p></div>
           </div>
    
              <div id="fza"><input onclick="Javascript:aceptar()" type="button" value="SUBMIT" name="Submit"/></div>
              <div id="fzb"><input type="reset" class="Button" value="ERASE"/></div>
            </div>
          </form>
          <form name="form-order" action="control.php" method=post target=_blank">
            <input type="hidden" name="operation"/> 
            <input type="hidden" name="Total"/> 
          </form>
    In the former version of this code, for its processing by asp, the collecting of data and information was different and the submission of "form" triggered the processing of "form-order".

    Now, an adaptation to php has modified everything.

    The javascript: document.form-order.submit();

    The problem is that the content of "form" is not submitted obviously.

    We can add: document.form.submit();

    But in this case the two forms are submitted, so the second form ("form-order") is processed whether the required fields in "form" are filled out or not. You are redirected to control.php and then to the bank page, and get another window with a message from "form", asking for the proper filling of the fields, resulting in two independent forms.

    There must be a way to process the first form and then, if the required fields are filled, trigger the function document.form-order.submit(); to get the second for submitted.

    I have tried different options with no result at all.

    My knowledge of js is not so good.

    I would appreciate some help on this issue.

    Thanks very much.

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>12345</title>
    <style>
    body{color:#000;background-color:#fff;font-family:Georgia,'Bookman Old Style',Verdana;font-size:14px;text-align:center;}
    input[type="text"]{text-align:center;margin-left:10px;}
    </style>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
    $(document).ready(function(){
    
    $('form,input').each(function(){
    if($(this).attr('name')&&!$(this).attr('id')){
    $(this).attr('id',$(this).attr('name'));
    }
    });
    
    $('#Submit').click(function(){
    var reqs=$('#required').val().split(','),
        valid=true,
    	params={},
    	fts='hidden,text',
    	url=$('#mailform').attr('action');
    for(var i=0; i<reqs.length; i++){
    if(!$('#'+reqs[i]).val()){valid=false;$('#'+reqs[i]).focus();break;}
    }
    if(valid){
    $('#mailform input').each(function(){
    if( fts.indexOf($(this).attr('type')) !=-1 ){
    params[$(this).attr('id')]=$(this).val()||'';
    }
    });
    /*
    console.log(params);
    
    in Chrome console you can see smth like this:
    
    Object {order: "968", redirect: "", recipient: "online@the web site. com", subject: "Purchase", required: "Name,Address,E-Mail"…}
    Address: "2"
    E-Mail: "3"
    Name: "1"
    order: "968"
    recipient: "online@the web site. com"
    redirect: ""
    required: "Name,Address,E-Mail"
    subject: "Purchase"
    */
    $.post(url,params,function(data){
    if(data){
    /* 
    above goes condition if data is OK
    which now works with any data received from the server
    change it according to the expected data context
    */
    $('#orderform').submit();
    }
    else{
    alert('The first form is not sent!\nEverything went wrong...');
    return;
    }
    })
    }
    });
    });
    </script>
    </head>
    <body>
    <form name="mailform" action="http://cgi.the web site.com/FormMail.pl" method="post">
            <input type="hidden" value="968" name="order" /> 
            <input type="hidden" name="redirect" /> 
            <input type="hidden" value="online@the web site. com" name="recipient" /> 
            <input type="hidden" value="Purchase" name="subject" /> 
            <input name="required" type="hidden" value="Name,Address,E-Mail" />
              <h2>Personal Identification</h2>
                <div id="fa"><p>Full Name<input name="Name" type="text" id="Name" /></p></div>
            </div>
           <div id="fa">
              <h2>Contact Details</h2>
                <div id="fab"><p>Address<input name="Address" type="text" id="Address" /></p></div>
                <div id="fac"><p>E-Mail<input name="E-Mail" type="text" id="E-Mail" /></p></div>
           </div>
    
              <div id="fza"><input type="button" value="SUBMIT" name="Submit" /></div>
              <div id="fzb"><input type="reset" class="Button" value="ERASE" /></div>
            </div>
          </form>
          <form name="orderform" action="control.php" method="post" target="_blank">
            <input type="hidden" name="operation" /> 
            <input type="hidden" name="Total" /> 
          </form>
    	  </body>
    </html>
    signature under construction

  3. #3
    Join Date
    Jan 2014
    Posts
    1
    It is important to choose right one since the first time. Nice post to hang on. I really loved it the way of the stuff provided in this article.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14919 seconds
  • Memory Usage 2,877KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates