Jump to content

[SOLVED] Two forms on one page.. any tips or tricks?


JTapp

Recommended Posts

I'm trying to make two forms work on one page.  They are both comprehensive search forms - one returns results from two tables, the other returns results from three other tables.  Does anybody have any suggestions or links for me.. I can only get one form to work.

Thanks!

Link to comment
Share on other sites

What problems are you having?  "only one works" isn't a helpful description of the problem.

 

<form action="script1.php" method="post">
  ...
  <input type="submit" name="submit" value="Submit form one" />
</form>

<form method="script2.php" method="post">
  ...
  <input type="submit" name="submit" value="Submit form two" />
</form>

Link to comment
Share on other sites

I'd have to agree with the radio button idea but if you really do want two separate forms, you could do the following:

 

<form name=form1 action=destination.php method=post>
<input type=text name=editbox1>
<input type=submit name=frm1Submit>
</form>

<form name=form2 action=destination.php method=post>
<input type=text name=editbox2>
<input type=submit name=frm2Submit>
</form>

 

in this case, the action page is the same. 

 

You'd then have code in the action page that would check to see which submit button was pressed:

 

if(isset($_POST['frm1Submit'){//process form1}
if(isset($_POST['frm2Submit'){//process form2}

 

Or you could change the forms to use two different action pages--depending on which button was pressed, a different page would come up.

Link to comment
Share on other sites

Well, here is the code (it's immature because I'm new at this).

The second form works, but the first form - with the methode list returns nothing - regardless of what search parameters I put.

 

<form method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/3results.php"; target="_blank">
<p class="style1"> </p>
<p class="style1"><img src="ldgePhotos/lodgelocator.gif" alt="LodgeLocator" width="370" height="53"></p>
<p class="style1"> </p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="544" height="183">
<p align="center">
<select name="metode" size="6">
<option value="tblLodges.strLodgeName" selected>Name of Lodge</option>
<option value="tblLodges.intLodgeNumber">Lodge Number</option>
<option value="tblLodges.intDistrictID">District Lodge Is In</option>
<option value="tblLodges.strLodgeMailingCity">City Lodge Is Located In</option>
<option value="tblLodges.strLodgeMailingPostCode">Zip Code of Lodge Location</option>
<option value="tblLodges.strLodgeCounty">Lodge Parish</option>
</select>
<span class="style9">Search Value:</span> 
<input name="search2" type="text" class="form" size="25">
</p>
<p align="center"> </p>


<div align="center">
<input type="submit" value="Click Here To Search Our Lodge Locator!!" name="GOTWO">
</p>
</div></td>
</tr>
</table>
<hr>
</form></td>
<p> </p>
<table class="auto" width="811">
<tr> 
<td width="803" height="510" class="row2"> 
<table width="79%" height="58%">
<tr> 
<td height="245" bgcolor="#E9E7D8" valign="top"> 
<table cellpadding="0" cellspacing="0" border="2" style=" height:25%;" height="57%" width="102%">
<tr valign="top" bgcolor="#E9E7D8"> 
<td height="194" align="center" valign="middle" bordercolor="#666633">
<form method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/5results.php"; target="_blank">
<p class="style1"><img src="ldgePhotos/districtdetails.gif" alt="distdetails" width="370" height="53"></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td bordercolor="#000000">
<p> </p>

<p align="center">
<input type="hidden" name="metode" value="tblLodges.intDistrictID"/>
</select>
<p> </p>
<p align="center"<span class="style9">Enter District Number:</span> 
<input name="search" type="text" class="form" size="5">
</p>
<div align="center">
<input type="submit" value="Click Here To View District Details" name="Go">
</p>
<p align="center"> </p></td>
</tr>
</table>
</form></td>

Link to comment
Share on other sites

Here is the PHP code - again, I'm new.. be gentle with me on my sloppy code:

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
                              <tbody>

                                <tr>
                                  <td width="100%"><p align="center"><span class="style2">    Grand Lodge of Florida Lodge Locator</span><br />
                                  </p></td>
                                </tr>
                              </tbody>
</table>

                            <center>
                            </center>

                            <center>
                              <br />
                              <br />
                              <table border="1" cellpadding="4" cellspacing="0" width="86%">
                                <tbody>
                                  <tr>
                                    <td colspan="5" bgcolor="FFFF99" height="18"><center>
                                        <strong>Results Of Your Search </strong>
                                    </center></td>
                                  </tr>
                                  <tr>
                                    <td width="13%" height="18" align="center" bgcolor="FFFF99"><center>
                                      Lodge ID Number
                                    </center></td>
                                    <td width="19%" height="18" align="center" bgcolor="FFFF99"><center>
                                      Lodge Name
                                    </center></td>
                                    <td width="20%" align="center" bgcolor="FFFF99"> Click  
                                    Button To View <strong>Lodge Details </strong></td>
                                    <td width="18%" height="18" align="center" bgcolor="FFFF99"><center>
                                      City
                                    </center></td>
                                    <td width="10%" height="18" align="center" bgcolor="FFFF99"><center>
                                      District 
                                    Number
                                    </center></td>
                                  </tr>
                                  




<?php
$username = "username";
$password = "password";
$hostname = "localhost"; 

$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db("database",$dbhandle)
or die("Could not select database");

$query = mysql_query("SELECT strLodgeName, intLodgeNumber, intDistrictID, strLodgeMailingCity, strLodgeMailingPostCode FROM tblLodges WHERE TRIM(LEADING '0' FROM $metode) = '$search' GROUP BY strLodgeName LIMIT 50");
while ($row = @mysql_fetch_array($query))

{
echo "<tr bgcolor=\"#dddddd\"><td><center>";
echo $row["intLodgeNumber"];
echo "</center></td><td><center>";
echo $row["strLodgeName"];
echo "</center></td><td><center><span class=\"style2\">";
echo "<input name=\"submit\" type=\"button\" value=\"Lodge Details\" onclick=\"javascript:window.location='3view.php?id=";
echo $row["intLodgeNumber"];
echo "'\" /></center></td>";
echo "</center></td><td><center>";
echo $row["strLodgeMailingCity"];
echo "</center></td><td><center>";
echo ltrim($row["intDistrictID"], '0');
}?>
                                </tbody>
                              </table>
                              <br />
                            </center>


</body>
</html>

Link to comment
Share on other sites

Try cleaning up your html...there is unclosed tags everywhere and other mistakes that can interfere. 

 

Why is there a semi-colon in the form declaration? 

<form method="post" action="http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/3results.php"; target="_blank">

 

There is a span in the middle of a paragraph tag:

<p align="center"<span class="style9">Enter District Number:</span> 

 

Your html doesn't necessarily need to validate, but if you're having problems, it usually a good step to go back, clean up, and make sure that all your tags match up.

Link to comment
Share on other sites

It's quite possible that the HTML code is fine now but the PHP code doesn't output anything.  Which form does NOT work?  Can we see the code from the action script for THAT form?  If possible only show the code that actually processes that form.

Link to comment
Share on other sites

Here is my online testing page: http://www.glflamason.org/NEWSITE/NEW2/lodgelocator/5search.php

 

The second form - closer to the bottom (District Details), works fine - use "6" if you want to try it out.

 

The first form (Lodge Locater) DOES NOT WORK - parameters to try are: "Tuscan" for 'Name of Lodge' or "6" for 'District Lodge is In'.

The first form is pointed to 3results.php and I posted the code earlier, but here it is:

The code works fine when it is the only form on the page....

 

<?php
$username = "username";
$password = "password";
$hostname = "localhost"; 

$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db("database",$dbhandle)
or die("Could not select database");

$query = mysql_query("SELECT strLodgeName, intLodgeNumber, intDistrictID, strLodgeMailingCity, strLodgeMailingPostCode FROM tblLodges WHERE TRIM(LEADING '0' FROM $metode) = '$search' GROUP BY strLodgeName LIMIT 50");
while ($row = @mysql_fetch_array($query))

{
echo "<tr bgcolor=\"#dddddd\"><td><center>";
echo $row["intLodgeNumber"];
echo "</center></td><td><center>";
echo $row["strLodgeName"];
echo "</center></td><td><center><span class=\"style2\">";
echo "<input name=\"submit\" type=\"button\" value=\"Lodge Details\" onclick=\"javascript:window.location='3view.php?id=";
echo $row["intLodgeNumber"];
echo "'\" /></center></td>";
echo "</center></td><td><center>";
echo $row["strLodgeMailingCity"];
echo "</center></td><td><center>";
echo ltrim($row["intDistrictID"], '0');
}?>

 

Thanks for your time!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.