开发者

I have two forms on a page but the submit button is submitting both forms

开发者 https://www.devze.com 2023-03-26 22:09 出处:网络
Hi I have two forms on a page, one is a small newsletter sign up form and the other is a larger event booking form. when the large booking form is submitted it submits the small newsletter form aswell

Hi I have two forms on a page, one is a small newsletter sign up form and the other is a larger event booking form. when the large booking form is submitted it submits the small newsletter form aswell. think it has something to do with the action url.

Here is the page code:

 <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" />
开发者_StackOverflow中文版    <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:info@tis.org.uk">info@tis.org.uk       </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>


I dont think it is submitting the form twice, i think that the variable "submitform" = yes is being set by both, so when you click through to the large form it thinks that form 2 has been submitted also - but in reality it hasn't... you probably want to check that the form has really been submitted using the $_POST variables.

0

精彩评论

暂无评论...
验证码 换一张
取 消