Solved

Submit/return submitting 2 forms at once

Posted on 2011-09-21
2
335 Views
Last Modified: 2012-05-12
I have a page which has two separate forms. A registration form and a 'join a newsletter' form at the bottom of the screen.

When I click submit on the registration form both forms are submitted. Is there a way to just submit the main registration form?

http://www.anjoman.co.uk/registerworks2.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Join Anjoman</title>

  <?php include("includes/footer.php"); ?>   
<?php include("includes/header.php"); ?></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="top3">
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="697" valign="top"><img src="img/topcurve.jpg" width="1008" height="23" alt="topcurve" /></td>
          </tr>
          <tr>
            <td align="center" valign="top" class="middlecurve"><table width="95%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center"><table width="93%" border="0" cellspacing="0" cellpadding="6">
                  <tr>
                    <td><h1>Join Anjoman</h1>
                      <p>If you wish to join Anjoman you must complete and submit the form below or<a href="anjoman_application_form.pdf" target="_new"> click here to download  an Application Form. </a></p></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td align="center"><table width="905" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><img src="img/greytop.jpg" width="905" height="25" alt="top" /></td>
                  </tr>
                  <tr>
                    <td align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="formmiddle">
                      <tr>
                        <td align="center"><table width="830" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td align="center"><table width="830" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td><?php if (isset($_POST['submitted'])) { // Handle the form.

	require_once (MYSQL);
	
	// Trim all the incoming data:
	$trimmed = array_map('trim', $_POST);
	
	// Assume invalid values:
	$fn = $ln = $e = $p = FALSE;
	
	// Check for a first name:
	if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) {
		$fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']);
	} else {
		echo '<p class="error">Please enter your first name!</p>';
	}
	
	// Check for a last name:
	if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) {
		$ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']);
	} else {
		echo '<p class="error">Please enter your last name!</p>';
	}
	
	// Check for a tel:
	if (preg_match ('/^[0-9 \'.-]{2,40}$/i', $trimmed['tel'])) {
		$te = mysqli_real_escape_string ($dbc, $trimmed['tel']);
	} else {
		echo '<p class="error">Please enter telephone number</p>';
	}
	
	// Check for a fax:
	
		$fa = mysqli_real_escape_string ($dbc, $trimmed['fax']);
	
	
	// Check for company:
	if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['company'])) {
		$co = mysqli_real_escape_string ($dbc, $trimmed['company']);
	} else {
		echo '<p class="error">Please enter your last name!</p>';
	}
	
		// Check for type of business:
	if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['type_business'])) {
		$ty = mysqli_real_escape_string ($dbc, $trimmed['type_business']);
	} else {
		echo '<p class="error">Please enter your business type!</p>';
	}
	
	// Check for an address:
	 {
		$ad = mysqli_real_escape_string ($dbc, $trimmed['address']);
	} 
	
	// Check for proposing member1:
	 {
		$pr1 = mysqli_real_escape_string ($dbc, $trimmed['propose1']);
	} 
	
	// Check for proposing member 2:
	 {
		$pr2 = mysqli_real_escape_string ($dbc, $trimmed['propose2']);
	} 
	
	// Check for member:
	$me = 'member';
	
	// Check for an email address:
	if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) {
		$e = mysqli_real_escape_string ($dbc, $trimmed['email']);
	} else {
		echo '<p class="error">Please enter a valid email address!</p>';
	}

	// Check for a password and match against the confirmed password:
	if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) {
		if ($trimmed['password1'] == $trimmed['password2']) {
			$p = mysqli_real_escape_string ($dbc, $trimmed['password1']);
		} else {
			echo '<p class="error">Your password did not match the confirmed password!</p>';
		}
	} else {
		echo '<p class="error">Please enter a valid password!</p>';
	}
	
	

	
	if ($fn && $ln && $e && $p) { // If everything's OK...

		// Make sure the email address is available:
		$q = "SELECT user_id FROM users WHERE email='$e'";
		$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
		
		if (mysqli_num_rows($r) == 0) { // Available.
		
			// Create the activation code:
			$a = md5(uniqid(rand(), true));
			
$bd = mysqli_real_escape_string($dbc, $trimmed['bdayday']);
$bm = mysqli_real_escape_string($dbc, $trimmed['bdaymonth']);
$by = mysqli_real_escape_string($dbc, $trimmed['bdayyear']);
$birthday = $by."//".$bm."//".$bd;


		
			// Add the user to the database:
	$q = "INSERT INTO users (email, pass, first_name, last_name, active, company, type_business, member, tel, fax, address, registration_date, bday, prop1, prop2) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', '$co', '$ty', '$me', '$te', '$fa', '$ad', NOW() , '$birthday', '$pr1', '$pr2')";
	
			$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

			if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
			
				// Send the email:
				$body = "Thank you for registering at <whatever site>. To activate your account, please click on this link:\n\n";
				$body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a";
				 mail($trimmed['email'] . ', registration@anjoman.co.uk', 'Registration Confirmation', $body, 'From: registration@anjoman.co.uk');

				
				// Finish the page:
				echo '<h3>Thank you for registering! </br>A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>';
				
			
				
			} else { // If it did not run OK.
				echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
			}
			
		} else { // The email address is not available.
			echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>';
		}
		
	} else { // If one of the data tests failed.
		echo '<p class="error">Please re-enter your passwords and try again.</p>';
	}

	mysqli_close($dbc);

} // End of the main Submit conditional.
?></td>
                              </tr>
                            </table></td>
                          </tr>
                          <tr>
                            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td><form action="registerworks2.php" method="post">
                                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                      <td width="52%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
                                        <tr>
                                          <td>First Name</td>
                                          <td valign="top"><input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" /></td>
                                        </tr>
                                        <tr>
                                          <td>Last Name</td>
                                          <td><input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" /></td>
                                        </tr>
                                        <tr>
                                          <td>Date of Birth</td>
                                          <td>DD
                                            
                                            <select name="bdayday" id="bdayday">
                                              <option value="01">1</option>
                                              <option value="02">2</option>
                                            </select> 
                                            MM
                                            
                                            <select name="bdaymonth" id="bdaymonth">
                                              <option value="01">1</option>
                                              <option value="02">2</option>
                                            </select> 
                                            YY
                                            <select name="bdayyear" id="bdayyear">
                                              <option value="1920">1920</option>
                                              <option value="1921">1921</option>
                                              <option value="1922">1922</option>
                                            </select></td>
                                        </tr>
                                        <tr>
                                          <td>Email Address</td>
                                          <td><input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /></td>
                                        </tr>
                                        <tr>
                                          <td>Telephone</td>
                                          <td><input name="tel" type="text" id="tel" value="<?php if (isset($trimmed['tel'])) echo $trimmed['tel']; ?>" size="30" maxlength="80" /></td>
                                        </tr>
                                        <tr>
                                          <td>Fax</td>
                                          <td><input name="fax" type="text" id="fax" value="<?php if (isset($trimmed['fax'])) echo $trimmed['fax']; ?>" size="30" maxlength="80" /></td>
                                        </tr>
                                        <tr>
                                          <td>Company</td>
                                          <td><input type="text" name="company" id="company" value="<?php if (isset($trimmed['company'])) echo $trimmed['company']; ?>"/></td>
                                        </tr>
                                        <tr>
                                          <td>Type of Business</td>
                                          <td><input type="text" name="type_business" id="type_business" value="<?php if (isset($trimmed['type_business'])) echo $trimmed['type_business']; ?>"/></td>
                                        </tr>
                                        <tr>
                                          <td valign="top">Address</td>
                                          <td><textarea name="address" id="address" value="<?php if (isset($trimmed['address'])) echo $trimmed['address']; ?>"cols="30" rows="5"></textarea></td>
                                        </tr>
                                        </table></td>
                                      <td width="48%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
                                        <tr>
                                          <td valign="top">Membership Type</td>
                                          <td><span class="copy">
                                            <label for="Membership">
                                              <input name="member" type="radio" id="radio" value="Guest" checked="checked" />
                                              Guest<br />
                                              <input type="radio" name="member" id="radio" value="Premium Individual" />
                                              Premium Individual <br />
                                              <input name="member" type="radio" id="radio" value="Premium Business" />
                                              Premium Corporate <br />
                                              </label>
                                            </span></td>
                                        </tr>
                                        <tr>
                                          <td>Password<br />                                            
                                            <small class="bottomcopy"><em>(Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long)</em></small></td>
                                          <td valign="top"><input type="password" name="password1" size="20" maxlength="20" /></td>
                                        </tr>
                                        <tr>
                                          <td>Confirm Password</td>
                                          <td><input type="password" name="password2" size="20" maxlength="20" /></td>
                                        </tr>
                                        <tr>
                                          <td>Name of proposing member<br />
                                            <small class="bottomcopy"><em>(Premium members only)</em></small></td>
                                          <td valign="top"><input name="propose1" type="text" id="propose1" size="20" maxlength="20" /></td>
                                        </tr>
                                        <tr>
                                          <td>Name of seconding member<br />
                                            <small class="bottomcopy"><em>(Premium members only)</em></small></td>
                                          <td valign="top"><input name="propose2" type="text" id="propose2" size="20" maxlength="20" /></td>
                                        </tr>
                                      </table></td>
                                    </tr>
                                  </table>
                                  <div align="center">
                                    <input type="submit" name="submit" value="Register" />
                                </div>
                                  <input type="hidden" name="submitted" value="TRUE" />
                                </form></td>
                                </tr>
                              </table></td>
                          </tr>
                        </table></td>
                      </tr>
                      </table></td>
                  </tr>
                  <tr>
                    <td><img src="img/greybottom.jpg" width="905" height="28" alt="bottom" /></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td align="center"><table width="905" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><img src="img/topsmall.jpg" width="905" height="26" alt="top" /></td>
                    </tr>
                  <tr>
                    <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="longmiddle">
                      <tr>
                        <td align="center"><table width="95%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><form action="anjoman.php" method="post" name="SampleForm" id="SampleForm2">
                              <table width="100%" border="0" cellpadding="0" cellspacing="0" class="formcopy">
                                <tr>
                                  <td><table width="100%" border="0" cellpadding="5" cellspacing="0" class="applicationfor">
                                    <tr>
                                      <td class="priceblue">There are currently three categories of Membership:</td>
                                      </tr>
                                    </table></td>
                                  </tr>
                                <tr>
                                  <td><table width="100%" border="0" cellspacing="0" cellpadding="6">
                                    <tr>
                                      <td width="32%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="10">
                                        <tr>
                                          <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="2">
                                            <tr>
                                              <td><span class="copy"><strong><span class="infoboxblue">GUEST MEMBERSHIP</span><br />
                                                </strong></span></td>
                                              </tr>
                                            <tr>
                                              <td><span class="copysmaller">Open to individuals over the age of 21 year</span><span class="copy">s <br />
                                                <span class="infoboxblue"><strong>£FREE</strong></span></span></td>
                                              </tr>
                                            </table></td>
                                          </tr>
                                        <tr>
                                          <td valign="top" bgcolor="#FFFFFF"><p>For guest membership please fill out and submit the form above. When you submit the form you will recieve an activation code in your email. Click the link in your email to activate your account. You can then log in to book on our Monthly Meetings and events.</p>
                                            <p>You can upgrade your membership to premium at any time.</p></td>
                                          </tr>
                                        </table></td>
                                      <td width="34%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="10">
                                        <tr>
                                          <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="2">
                                            <tr>
                                              <td><span class="copy"><strong><span class="infoboxblue">PREMIUM INDIVIDUAL MEMBERSHIP </span><br />
                                                </strong></span></td>
                                              </tr>
                                            <tr>
                                              <td><span class="copysmaller">Open to individuals over the age of 21 years </span><span class="copy"><br />
                                                <span class="infoboxblue"><strong>£120 per annum</strong></span></span></td>
                                              </tr>
                                            </table></td>
                                          </tr>
                                        <tr>
                                          <td valign="top" bgcolor="#FFFFFF"><p>Premium membership of Anjoman is open to all individuals over the age of 21,  who are or have been engaged in business or the professions. </p>
                                            <p>Applications for premium membership should be  supported by two current members of Anjoman. Space has been provided on  the form where the applicant should obtain the signature of a  &ldquo;Proposing Member&rdquo; and a &ldquo;Seconding Member&rdquo;. <br />
                                              <br />
                                              Once completed, the <a href="anjoman_application_form.pdf">Application Form</a> together with your <strong>Annual Premium Membership Fees</strong> should be sent to the address indicated on the form. <br />
                                              <br />
                                              The Board of Management will consider  each application at its next Board Meeting and its decision will be  formally notified to the applicant by the Secretary of Anjoman.<br />
                                              <br />
                                              Successful applicants will also be  recognized and welcomed by an announcement in the following Monthly  Meeting of Anjoman. </p></td>
                                          </tr>
                                        </table>                                        <p class="copy">&nbsp;</p></td>
                                      <td width="34%" valign="top" class="copy">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="10">
                                          <tr>
                                            <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="2">
                                              <tr>
                                                <td><strong><span class="infoboxblue">PREMIUM CORPORATE MEMBERSHIP</span><br />
                                                  </strong></td>
                                                </tr>
                                              <tr>
                                                <td><span class="copysmaller">Open to all businesses/corporates. Corporate membership entitles up to   three persons from a company to the benefits of Anjoman membership </span><br />
                                                  <span class="infoboxblue"><strong>£300 per annum</strong></span></td>
                                                </tr>
                                              </table></td>
                                            </tr>
                                          <tr>
                                            <td valign="top" bgcolor="#FFFFFF"><p>Anjoman members benefit from discounted charges for the attendance of the Monthly Meetings. <strong>Typically</strong>, the cost of entry to the Monthly Meetings is <strong>£40 </strong>for premium members, and <strong>£50</strong> for guest members. <br />
                                                <br />
Premium members are given priority to promote  their businesses and/or professional activities during  Monthly Meetings  and other events. Premium members may also showcase their products and services  in either the Monthly Meetings during the pre-dinner session, or  through taking advantage of sponsorship opportunities offered by  Anjoman. <br />
<br />
Premium members are treated preferentially for  all Anjoman meetings and events in situations where, due to  over-booking, a waiting list procedures is being operated. <br />
<br />
Only premium members are  eligible to serve on  the Board of Anjoman. Please see Anjoman's Constitution for details of  eligibility. <br />
<br />
Above all, by virtue of premium membership and  subsequent participation, each member ensures that Anjoman thrives as  an organization dedicated to the promotion of the British-Iranian  Business and Professional community in the United Kingdom. </p></td>
                                            </tr>
                                          </table>
                                </td>
                                    </tr>
                                    </table></td>
                                  </tr>
                                </table>
                              </form></td>
                            </tr>
                          </table></td>
                        </tr>
                      </table></td>
                    </tr>
                  <tr>
                    <td><img src="img/bottomsmall.jpg" width="905" height="27" alt="bottom" /></td>
                    </tr>
                  </table></td>
              </tr>
              </table></td>
          </tr>
          <tr>
            <td valign="top"><img src="img/bottomcurve.jpg" width="1008" height="25" alt="bottomcurve" /></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top"><?php include("includes/footerlinks.html"); ?></td>
      </tr>
    </table></td>
  </tr>
</table>
<script type="text/javascript">
var sprycheckbox2 = new Spry.Widget.ValidationCheckbox("sprycheckbox2");
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1", {contentIsOpen:false});
</script>
</body>
</html>

Open in new window

0
Comment
Question by:BrighteyesDesign
2 Comments
 
LVL 14

Accepted Solution

by:
Kalpan earned 500 total points
ID: 36572201
keep it with different form tag and with different submit button name or value

than do the following

if(isset($_POST['submit1'])){
   // TO DO
}

if(isset($_POST['submit2'])){
   // TO DO
}
0
 

Author Closing Comment

by:BrighteyesDesign
ID: 36572431
Thanks for that
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now