Jump to content

Recommended Posts

hello i am corrently doing some work for a customer and due to the formating he wants  on his site i have found that they only way i can give him what he wants it with 2 forms for submiting data problem is he only wants one submit botten

i cant figure out how to if possably to do it i sliped this together
[code]
<SCRIPT LANGUAGE="JavaScript">
<!--
function Envia()
{
document.Category.submit();
document.Suburbs.submit();
}
//-->
</SCRIPT>
[/code]
at first i couldnt understand why it wasnt working till i realed it would be submiting them both but now as 1 submitions

both forms contains different data and both need to be passed to the same page

i am wondering if there is maybe a way to link two forms together to make them one but still allow for other text and tables in between ....... eather that or i was considering that maybe i could make an "hidden" form and when the user clicks the submit botten it loads both of my shown forms in to the hiden one and then submits it as a single submit  ....problem is i dont know how to do eather of the above

i am hopeing some one can get back to me with an easy sulution

thank you for your time
chris
Link to comment
https://forums.phpfreaks.com/topic/15691-2-forms-1-submit/
Share on other sites

Are these forms displayed at the same time or can they be displayed at different times?

If they have to be displayed at the same time, you can name each field appropriately, so that when your PHP script recieves the submitted data, your logic can do the "right thing".

For example, consider this form:
[code]
<form method="post" action="process.php">
Form1 Field1: <input name="form1[field1]" type="text"><br>
Form1 Field2: <input name="form1[field2]" type="text"><br>
<hr>
Form2 Field1: <input name="form2[field1]" type="text"><br>
Form2 Field2: <input name="form2[field2]" type="text"><br>
<hr>
<input type="submit" name="submit" value="Send Data">
</form>
[/code]
The in the script process.php:
[code]<?php
// code to process Form1
foreach($_POST['form1'] as $fld)
    switch ($fld) {
        case 'field1':
//
//  code to process field1
//
            break;
        case 'field2':
//
//  code to process field2
//
            break;
    }
//
// end of code to process form1
//
// code to process Form2
foreach($_POST['form2'] as $fld)
    switch ($fld) {
        case 'field1':
//
//  code to process field1
//
            break;
        case 'field2':
//
//  code to process field2
//
            break;
    }
//
// end of code to process form 2
//
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/15691-2-forms-1-submit/#findComment-64041
Share on other sites

ok im the header i have a java script at this point
[code]
<SCRIPT LANGUAGE="JavaScript">
<!--
function Envia()
{
document.Suburbs.submit();
document.Category.submit();
}
//-->
</SCRIPT>
[/code]

and the forms i am haveing troble with below:

[code]
<form NAME="Suburbs" action="results.php" method="POST">
<input id="tb" name="tb" value="" class="enterSuburb" tabindex="1" autocomplete="off" onkeyup="javascript:sfsComplete();" type="text">
</span>
</div>
<div class="row">
<label class="selectSuburbs"><strong>Or Select Suburbs:</strong></label>
<p><span>Select from list
      <select id="u" name="u" size="5" class="suburbsList" onclick="javascript:sfsInsert();" action="results.php" method="post">
        <option selected="selected" value="">*** SHOW ALL SUBURBS ***</option>
        <option>ABBOTSBURY</option>
        <option>ABBOTSFORD</option>
      </select>
 
</span>
 
  </p>
<p><span class="surroundingSuburbs">
        <input id="is" name="is" value="1" tabindex="20" checked="checked" type="checkbox">
    Include Surrounding Suburbs
      </span>
   
</p>
</div>
</fieldset>


<fieldset class="bottom">
<br>
</form>
</fieldset>




</div>
</div>
</td>
<td><img src="images/e03.gif" width="15" height="298" alt="" border="0"></td>
<td bgcolor="#D1D6DB" background="images/fon01.jpg" width="33%" style="background-position: top; background-repeat: repeat-x;">

<div id="searchForm">
<div id="searchHeader"><strong>Search for Business by Category</strong></div>
      <script type="text/javascript">
//<![CDATA[
var Category_sfsIndex      = new Object;
Category_sfsIndex.populated = false;
/*
Typing a name into the suburb entry field will scroll the suburb select
field to a matching suburb name (if any).
*/
function Category_sfsComplete () {
if (!document.getElementById) return;
var text  = document.getElementById('Type_Category');
var select = document.getElementById('Select_Category');
if (!Category_sfsIndex.populated) Category_sfsBuildIndex();
var suburb = text.value.match(/,*([^,]+)$/);
if (suburb) {
var name = suburb[1].toUpperCase().replace(/^\s*/, '').replace(/\s*$/, '');
for (var i = Category_sfsIndex[name.charAt(0)]; i < select.options.length; i++) {
if (select.options[i].text.toUpperCase().indexOf(name) == 0) {
select.selectedIndex = i;
break;
}
else {
select.selectedIndex = -1;
}
}
}
}
/*
On click event for the suburb select box. When clicked it populates
the suburb entry field then deselects the clicked suburb. Focus is
returned to the suburb entry field.
*/
function Category_sfsInsert () {
if (!document.getElementById) return false;
var text    = document.getElementById('Type_Category');
var select  = document.getElementById('Select_Category');
// An IE bug means we need another event before select.selectedIndex
// will update from -1. Since we need to swap the focus anyway we'll
// do it before we look at what was clicked in the select box.
text.focus();
var suburb = select.options[select.selectedIndex];
// short circuit on 'show all suburbs'
if (select.selectedIndex == 0) {
text.value = '';
return true;
}
// see if the selected suburb is in the list already
var textSuburbs = text.value.split(/\s*,\s*/);
if (!textSuburbs) return false;
var pattern = new RegExp('\s*' + suburb.text + '\s*$');
for (var i = 0; i < textSuburbs.length; i++) {
// if it's in the list don't do anything
if (pattern.exec(textSuburbs[i])) return false;
}
// its not in the list so lets add it replacing any incomplete words
var newvalue = text.value.replace(
/(^|,)([^,]*)$/,
"$1 " + suburb.text + ', '
);
text.value = newvalue;
return false;
}
/*
Builds an index based on the first occurrence of suburb starting with a
letter. This speeds up the 'for' search of the select because we can
then skip straight to suburbs starting with that letter.
*/
function Category_sfsBuildIndex () {
if (!document.getElementById) return;
var select = document.getElementById('Select_Category');
for (var i = select.options.length; i--;) {
Category_sfsIndex[select.options[i].text.toUpperCase().charAt(0)] = i;
}
Category_sfsIndex.populated = true;
}
//]]>
  </script>
<fieldset class="top">
<div class="row">
<label><em><strong>2. </strong></em><strong>Enter Category:</strong></label>
<span>Type Category
<form NAME="Category" action="results.php" method="post">
<input id="Type_Category" name="Type_Category" value="" class="enterSuburb" tabindex="1" autocomplete="off" onkeyup="javascript:Category_sfsComplete();" type="text">
</span>
</div>
<div class="row">
<label class="selectSuburbs"><strong>Or Select Category:</strong></label>
<p><span>Select from list
      <select id="Select_Category" name="Select_Category" size="5" class="suburbsList" onclick="javascript:Category_sfsInsert();" action="results.php" method="post">
  <option>Select Category Below</option>

<?
// Select all the fields in all the records of the Employees table
$query =
        "SELECT catagory
      FROM catagory
ORDER BY catagory";

$result = mysql_query($query);

// Determine the number of enterys
$number = mysql_num_rows($result);
// if somthing hs gorn wrong let at least try and throw an error message
if ($number == 0) {
  print "Sorry, some one made a boo boo there is a code error please contact the admin <br><br>$query<br><br>";
} else {
  // Print the employee names
  for($i=0; $i<$number; $i++){
  $catagory = mysql_result($result,$i,"catagory");
        print "<option> $catagory<br> </option>";
  }
}

?>



      </select>
 
</span>
 
  </p>
<p><span class="surroundingSuburbs">
        <input id="all_Category" name="all_Category" value="0" tabindex="20" checked="checked" type="checkbox">
    Select All Category
      </span>
   
</p>
</div>
</fieldset>


<fieldset class="bottom">
<!--<input class="startSearch" value="start your search" tabindex="4" onclick="javascript:searchOnce();" type="button">-->
</form>

<INPUT TYPE="button" value="Enviar" onClick="Envia()">
[/code]

i have removed options to make it shorter

basicly i would like to bundle the two forems together and drop the java if i can but if i cant anything to help would be nice
Link to comment
https://forums.phpfreaks.com/topic/15691-2-forms-1-submit/#findComment-64560
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.