2011-08-08 128 views
0

嗨我有兩種形式在一個頁面上,一個是一個小型通訊註冊表單,另一個是較大的事件預訂表單。當提交大型預訂表時,它也會提交小型的通訊表格。認爲它與動作url有關。我在頁面上有兩種形式,但提交按鈕提交這兩種形式

這裏是頁面代碼:

<script type="text/javascript"><!-- 
function validate(f){ 
var regex = /^\s*$/i; 
for(var i=0; i<f.elements.length; i++){ 
if(regex.test(f.elements[i].value)){ 
alert("Please fill in all fields."); 
f.elements[i].focus(); 
return false; 
} 
} 

if(f.user_email.value.indexOf('@',0)==-1 || f.user_email.value.indexOf('.',0)==-1) 
{ 
alert("You must provide a VALID email address."); 
f.user_email.focus(); 
return false; 
     } 
return true; 
} 
//--></script> 

<div id="eventform" /> 
<form action="/Booking?ename=testevent&edate=19%20October%202011&submitform=yes"  method="post" onsubmit='return validate(this);'> 

<fieldset class="fieldset"> 
<div class="leftform"> 
    <label for="booking_name">Event: </label><br class="nobr" /> 
    <input name="booking_name" type="text" id="booking_name" value="testevent" /> 
</div> 

<div class="rightform"> 
    <label for="event_date">Date: </label><br class="nobr" /> 
    <input name="event_date" type="text" id="event_date" value="19 October 2011" /> 
</div> 
<div class="clear"></div> 

<div class="leftform"> 
    <label for="user_name">Name: </label><br class="nobr" /> 

    <input name="user_name" type="text" id="user_name" /> 
</div> 
<div class="rightform"> 
    <label for="organisation">Organisation: </label><br class="nobr" /> 
    <input name="organisation" type="text" id="organisation" /> 
</div> 
<div class="clear"></div> 

<div class="leftform"> 

    <label for="address">Address: </label><br class="nobr" /> 
    <input name="address" type="text" id="address" /> 
</div> 
<div class="rightform"> 
    <label for="postcode">Postcode: </label><br class="nobr" /> 
    <input name="postcode" type="text" id="postcode" /> 
</div> 
<div class="clear"></div> 


<div class="leftform"> 
    <label for="user_telephone">Contact Number: </label><br class="nobr" /> 
    <input name="user_telephone" type="text" id="user_telephone" /> 
</div> 
<div class="rightform"> 
    <label for="user_email">Email Contact: </label><br class="nobr" /> 
    <input name="user_email" type="text" id="user_email" /> 
</div> 

<div class="clear"></div> 
<br /> 


<hr /> 

<h3>Attendees</h3> 
<p>Please list the name(s) and email address(s) of those you wish to book a place at the above event.</p> 

<div class="leftform"> 
    <input placeholder="Name" name="attendee1" type="text" id="attendee1" /> 
</div> 

<div class="rightform"> 
    <input placeholder="Email Address" name="attendee_email1" type="text" id="attendee_email1" /> 
</div> 
<div class="clear"></div> 

<div class="leftform"> 
    <input placeholder="Name" name="attendee2" type="text" id="attendee2" /> 
</div> 
<div class="rightform"> 
    <input placeholder="Email Address" name="attendee_email2" type="text" id="attendee_email2" /> 

</div> 
<div class="clear"></div> 

<div class="leftform"> 
    <input placeholder="Name" name="attendee3" type="text" id="attendee3" /> 
</div> 
<div class="rightform"> 
    <input placeholder="Email Address" name="attendee_email3" type="text" id="attendee_email3" /> 
</div> 
<div class="clear"></div> 


<div class="leftform"> 
    <input placeholder="Name" name="attendee4" type="text" id="attendee4" /> 
</div> 
<div class="rightform"> 
    <input placeholder="Email Address" name="attendee_email4" type="text" id="attendee_email4" /> 
</div> 
<div class="clear"></div> 

<div class="leftform"> 
    <input placeholder="Name" name="attendee5" type="text" id="attendee5" /> 

</div> 
<div class="rightform"> 
    <input placeholder="Email Address" name="attendee_email5" type="text" id="attendee_email5" /> 
</div> 
<div class="clear"></div> 
<br /> 

<hr /> 
<h3>Invoice Details</h3> 
<p>Please give details of where the invoice should be sent.</p> 


<label for="invoice_name">Name: </label><br class="nobr" /> 
<input name="invoice_name" type="text" id="invoice_name" /><br /> 

<label for="invoice_address">Address: </label><br class="nobr" /> 
<input name="invoice_address" type="text" id="invoice_address" /><br /> 

<label for="invoice_postcode">Postcode: </label><br class="nobr" /> 
<input name="invoice_postcode" type="text" id="invoice_postcode" /><br /> 


<p>Once we have received your booking form the person booking and those attending will receive a confirmation email confirming your places at the event and an invoice will be issued. 
If you have any questions please do not hesitate to contact.</p> 

</fieldset> 

<br /> 
<input id="bookingform_submit" class="submitform" type="submit" value="Submit" /> 
     <br /><br /> 
</form> 
    </div> 

    </div> 

    </div> 

<div class="clear"></div> 
</div></div> 
<!--/content--> 


    <!--footer--> 
<div id="outer-footer"> 
    <div id="footer"> 
    <div class="footer-1"> 
    <h6>Get in touch...</h6> 
    <ul> 
    <li>Suite 124-128 Baltic Chambers,50 Wellington Street Glasgow G2 6HJ.</li> 
    <li><span>Tel:</span> 0141 248 1242</li> 

    <li><span>Fax:</span> 0141 221 1911</li> 
    <li><span>Email Us:</span><a href="mailto:[email protected]">[email protected]  </a></li> 
    </ul> 
    </div> 
    <div class="footer-2"> 
    <h6>Join our newsletter...</h6> 

    <ul> 
    <li>Hear about the latest event and courses.</li> 


<script type="text/javascript"><!-- 
function validate(f){ 
var regex = /^\s*$/i; 
for(var i=0; i<f.elements.length; i++){ 
if(regex.test(f.elements[i].value)){ 
alert("Please fill in all fields."); 
f.elements[i].focus(); 
return false; 
} 
} 
if(f.user_email.value.indexOf('@',0)==-1 || f.user_email.value.indexOf('.',0)==-1) 
{ 
alert("You must provide a VALID email address."); 
f.user_email.focus(); 
return false; 
     } 
return true; 
} 
//--></script> 




<li> 
    <form action="./&submitform=yes" method="post"> 

<span class="input_space"> 

    <input name="user_name" id="user_name" type="text" align="left"  onblur="if(this.value=='')this.value='Your Name';" 
    onfocus="if(this.value=='Your Name')this.value='';" value="Your Name" /> 
    </span> 

<span> 
    <input name="user_email" id="user_email" type="text" align="left" onblur="if(this.value=='')this.value='Your Email Address';" 
    onfocus="if(this.value=='Your Email Address')this.value='';" value="Your Email  Address" /> 
    </span> 

    <input id="newsletterform_submit" type="submit" value="" class="submit-2" /> 
    </form> 
+0

你能發佈完整的代碼清單嗎?它可能是你有嵌套的形式.... – diagonalbatman

+0

頁面上的代碼是相當大的,你想我發佈整個事情? –

+0

是的,從表單開始的位置到結束最後一個表單的位置都可以。 – diagonalbatman

回答

0

我不認爲這是提交表單的兩倍,我認爲變量「submitform」 = yes,則是由兩種設定,所以當你點擊進入大型表單,它認爲表單2也已提交 - 但實際上它沒有...您可能想要檢查表單是否已經真正使用$ _POST變量提交。