php multiple form post

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

php multiple form post

Post by bradleyd »

Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello everyone,
I am trying to add to an existing php page. I need to add this new form to the page that searches the database with text box criteria, and then populates textboxes with information. I can get the textboxes to populate. The only problem I have is when I type in search criteria and hit submit it uses the already submit form on the existing php code. I need to hit submit after user types in search criteria.Then the boxes will populate. If that is all correct then procede with code that already existed. Here is what I have so far.(sorry for the length of code):

Code: Select all

<?php

session_start();
   
   
if (!isset($_SESSION['uid']))
{
      header('Location:index.php?redirection=' . urlencode($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']));
      exit;
}
include('config.php');
include('udf_functions.php');
// connect to DB
if(!isset($_POST['submit'])) //un_submitted form
{
        if (!isset($_REQUEST['last_message']))
        {
                $_REQUEST['last_message']='';
        }
      draw_header('Add New File');
      draw_menu($_SESSION['uid']);
      draw_status_bar('Add new document', $_REQUEST['last_message']);
      echo '<body bgcolor="white">';
      echo '<center>'."\n".'<table border="0" cellspacing="5" cellpadding="5">'."\n";
      //////////////////////////Get Current User's department id///////////////////
      $query ="SELECT user.department from user where user.id='$_SESSION[uid]'";
      $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
      if(mysql_num_rows($result) != 1) /////////////If somehow this user belongs to many departments, then error out.
      {
            header('Location:error.php?ec=14');
            exit; //non-unique error
      }
      list($current_user_dept) = mysql_fetch_row($result);
      //Get a list of department names and id to populate javascript obj//
      $query = "SELECT name, id FROM department ORDER by name";
      $result = mysql_query ($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
      $dept_data = $result;
      $index = 0;
      ///////Define a class that hold Department information (id, name, and rights)/////////
      //this class will be used to temporarily hold department information client-side wise//
        //new code*******************************************************
       $query = "SELECT * FROM TAXPM INNER JOIN ADDR ON TAXPM.TAXROLL_PIN=ADDR.ADDR_PIN  WHERE TAXROLL_PIN='$search' ";
     $result= mysql_query ($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
        if ($result) {
        while ($r = mysql_fetch_array($result)) { // Begin while
           $parcel = $r["TAXROLL_PIN"];
            $last = $r["OWN_LNAME"];
            $first = $r["OWN_FNAME1"];
            $first1 = $r["OWN_FNAME2"];
            $addr = $r["ADDR_STNUMF"];
            $addr1 = $r["ADDR_STNAME"];
            $addr2 = $r["ADDR_STDIR"];
            $addr3 = $r["ADDR_CITY"];
            $addr4 = $r["ADDR_ZIP"];
} // end while and new code**************************************************************
  }
   
      ?>
      <Script Language="JavaScript">
      
             //define a class like structure to hold multiple data
                function Department(name, id, rights)
                {
                         this.name = name;
                    this.id = id;
                    this.rights = rights;
                    this.isset_flag = false;
                    if (typeof(_department_prototype_called) == "undefined")
                    {
                               _department_prototype_called = true;
                               Department.prototype.getName = getName;
                              Department.prototype.getId = getId;
                              Department.prototype.getRights = getRights;
                               Department.prototype.setName = setName;
                               Department.prototype.setId = setId;
                               Department.prototype.setRights = setRights;
                               Department.prototype.issetFlag = issetFlag;
                               Department.prototype.setFlag = setFlag;

                    }
                      function setFlag(set_boolean)
                      {      this.isset_flag = set_boolean;      }

                         function getName()
                    {       return this.name;            }

                         function getId()
                    {       return this.id;                      }
                  
                        function getRights()
                        {      return parseInt(this.rights);            }

                        function setRights(rights)
                    {       this.rights = parseInt(rights); }

                          function setName(name)
                    {       this.name = name;               }

                        function setId(id)
                  {       this.id = id;         }

                        function issetFlag()
                  {       return this.isset_flag;         }
                }
      
      ///Create default_Setting and all_Setting obj for mass department setting/////
      var default_Setting_pos = 0;
      var all_Setting_pos = 1;
      var departments = new Array();
      var default_Setting = new Department("Default Setting for Unset Department", "0", "0");
      var all_Setting = new Department("All", "0", "0");
      departments[all_Setting_pos] = all_Setting;
      departments[default_Setting_pos] = default_Setting;
      /////////////////////////Populate Department obj////////////////////////////////
<?php
      while( list($dept_name, $dept_id) = mysql_fetch_row($result) )
      {
            if($dept_id == $current_user_dept)
            {        
                  echo 'departments[' . ($index+2) . '] = new Department("' . $dept_name . '", "' . $dept_id . '", "1")' . "\n";
            }
            else
            {
            echo 'departments[' . ($index+2) . '] = new Department("' . $dept_name . '", "' . $dept_id . '", "0")' . "\n";
        }
            $index++;
      }
      
?>
<?php
     
      </Script>
      <SCRIPT LANGUAGE="JavaScript" src="functions.js"></script>
      <!-- file upload formu using ENCTYPE -->
      
<p>
//*********new form************************************************************************
 <form  name="parcel " method="post" action=>
<table width=90% align=center>
<tr>
      <td width="10%"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong>search for:</strong></font></td>
      <td width="16%"><input type=text name='search' size=25 maxlength=155></td>
      <TD width="74%"><input name="submit" type=submit></TD>
    </tr>
      <td></td>
      <td>&nbsp; </td>
      <td>&nbsp;</td>
    </tr>
</table>
</form>
</p>
<p><table width="37%" border="0">
  <tr>
    <td><label>Parcel </label></td>
    <td><input name="parcel" value= "<?php echo($parcel )?>"  type="text" ></td>
  </tr>
  <tr>
    <td><label>Last Name</label></td>
    <td><input name="last2" value= "<?php echo($last )?>"  type="text"></td>
  </tr>
  <tr>
    <td><label>First Name</label></td>
    <td><input name="first1" value= "<?php echo($first )?>"  type="text"></td>
  </tr>
  <tr>
    <td><label>First2 Name</label></td>
    <td><input name="first22" value= "<?php echo($first1)?>"  type="text"></td>
  </tr>
  <tr>
    <td><label>Street Number</label></td>
    <td><input name="addr_num2" value= "<?php echo($addr)?>"  type="text"></td>
  </tr>
  <tr>
    <td><label>Street Name</label></td>
    <td><input name="st_name" value= "<?php echo($addr1)?>"  type="text"></td>
  </tr>
  <tr>
    <td><label>Street Direction</label></td>
    <td><input name="dir" value= "<?php echo($addr2)?>"  type="text"></td>
  </tr>
  <tr>
    <td><label>City</label></td>
    <td><input name="city" value= "<?php echo($addr3)?>"  type="text"></td>
  </tr>
  <tr>
    <td><label>Zip</label></td>
    <td><input name="zip" value= "<?php echo($addr4)?>"  type="text"></td>
  </tr>
</table> </p>
//************end new form************************************************************************
    <form name="main" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
      <input type="hidden" name="MAX_FILE_SIZE" value="50000000">
      <tr>
      <td>
      <a class="body" tabindex=1 href="help.html#Add_File_-_File_Location" onClick="return popup(this, 'Help')" style="text-decoration:none">File Location</a>
      </td>
      <td colspan=3><input tabindex="0" name="file" type="file">
    </td>
      </tr>
      <tr>
      <td>
      <a class="body" tabindex= href="help.html#Add_File_-_Category"  onClick="return popup(this, 'Help')" style="text-decoration:none">Category</a>
      </td>
      <td colspan=3><select tabindex=2 name="category" ><br>
<?php
      /////////////// Populate category drop down list//////////////
      $query = "SELECT id, name FROM category ORDER BY name";
      $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
      while(list($id, $name) = mysql_fetch_row($result))
      {
            echo '<option value="' . $id . '">' . $name . '</option>';
      }
      mysql_free_result ($result);
?>
      </select>
      </td>
      </tr>
<?php
      udf_add_file_form();
?>
      <!-- Set Department rights on the file -->
        <TR>
      <TD>
      <a class="body" href="help.html#Add_File_-_Department" onClick="return popup(this, 'Help')" style="text-decoration:none">Department</a>
      </TD>
                 <TD COLSPAN=3><SELECT tabindex=3 NAME="dept_drop_box" onChange ="loadDeptData(this.selectedIndex)">
                        <option value=0> Select a Department</option>
                        <option value=1> Default Setting for Unset Department</option>
                        <option value=2> All Departments</option>
<?php
      //////Populate department drop down list/////////////////
         $query = "SELECT id, name FROM department ORDER BY name";
         $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
    //since we want value to corepodant to group id, 2 must be added to compesate for the first two none group related options.
        while(list($id, $name) = mysql_fetch_row($result))
    {
          $id+=2;
          //don't put quotes around values.  javascript might not work
            echo '      <option value ="' . $id . '" name="' . $name . '">'. $name . '</option>' . "\n";  
    }
      mysql_free_result ($result);
?>
    </SELECT>
      </TD>
    </TR>
    <TR>
      <!-- Loading Authority radio_button group -->
      <TD><a tabindex="4" class="body" href="help.html#Add_File_-_Authority" onClick="return popup(this, 'Help')" style="text-decoration:none">Authority</a></td>
      <!-- <TD><a href="help.html" onClick="return popup(this, 'Help')">Authority</a></TD> -->
      <TD>
<?php
            $query = "SELECT RightId, Description FROM rights order by RightId";
            $result = mysql_query($query, $GLOBALS['connection']) or die("Error in querry: $query. " . mysql_error());
            while(list($RightId, $Description) = mysql_fetch_row($result))
            {      
                  echo $Description.'<input type ="radio" name ="'.$Description.'" value="' . $RightId . '" onClick="setData(this.name)"> |'."\n";
            }    
?>
      </TD>
      </TR>
      <tr>
      <td>
        <a class="body" href="help.html#Add_File_-_Description" onClick="return popup(this, 'Help')" style="text-decoration:none">Description</a>
        </td>
      <td colspan="3"><input tabindex="5" type="Text" name="description" size="50"></td>
      </tr>
      
      <tr>
      <td>
        <a class="body" href="help.html#Add_File_-_Comment" onClick="return popup(this, 'Help')" style="text-decoration:none">Comment</a>
        </td>
      <td colspan="3"><textarea tabindex="6" name="comment" rows="4" onchange="this.value=enforceLength(this.value, 255);"></textarea></td>
      </tr>

      <TABLE border="0" cellspacing="0" cellpadding="3" NOWRAP>
      <tr nowrap>
        <td colspan="2" NOWRAP><b>Specific Permissions Settings</b></td>
      </TR>
      <TR>
      <td valign="top" align="center"><a class="body" href="help.html#Rights_-_Forbidden" onClick="return popup(this, 'Help')" style="text-decoration:none">Forbidden</a></td>
      <td valign="top" align="center"><a class="body" href="help.html#Rights_-_View" onClick="return popup(this, 'Help')" style="text-decoration:none">View</a></td>
      <td valign="top" align="center"><a class="body" href="help.html#Rights_-_Read" onClick="return popup(this, 'Help')" style="text-decoration:none">Read</a></td>
      <td valign="top" align="center"><a class="body" href="help.html#Rights_-_Modify" onClick="return popup(this, 'Help')" style="text-decoration:none">Modify</a></td>
      <td valign="top" align="center"><a class="body" href="help.html#Rights_-_Admin" onClick="return popup(this, 'Help')" style="text-decoration:none">Admin</a></td>
      </tr>
      <tr>
      <td><select tabindex="8" name="forbidden[]" multiple size="10" onchange="changeForbiddenList(this, this.form);">
<?php
      
      // query to get a list of available users
            $query = "SELECT id, last_name, first_name FROM user ORDER BY last_name";
            $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
            //////////////////Forbidden////////////////////
            while(list($id, $last_name, $first_name) = mysql_fetch_row($result))
            {
                  $str = '<option value="' . $id . '"';
                  // select current user's name
                  $str .= '>'.$last_name.', '.$first_name.'</option>';
                  echo $str;
            }
            mysql_free_result ($result);
?>
      </select></td>
      <td><select tabindex="9" name="view[]" multiple size="10" onchange="changeList(this, this.form);">
<?php
            ////////////////////View//////////////////////////
            $query = "SELECT id, last_name, first_name FROM user ORDER BY last_name";
            $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
            //////////////////Forbidden////////////////////
            while(list($id, $last_name, $first_name) = mysql_fetch_row($result))
            {
                  $str = '<option value="' . $id . '"';
                  // select current user's name
                  if($id == $_SESSION['uid']) {$str .= ' selected';}
                  $str .= '>'.$last_name.', '.$first_name.'</option>';
                  echo $str;
            }
            mysql_free_result ($result);
?>
      </SELECT></td>
      <td><select tabindex="10"  name="read[]" multiple size="10"onchange="changeList(this, this.form);">
<?php
      ////////////////////Read//////////////////////////
      $query = "SELECT id, last_name, first_name FROM user ORDER BY last_name";
            $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
            //////////////////Forbidden////////////////////
            while(list($id, $last_name, $first_name) = mysql_fetch_row($result))
            {
                  $str = '<option value="' . $id . '"';
                  // select current user's name
                  
                  if($id == $_SESSION['uid']) {$str .= ' selected';}
                  $str .= '>'.$last_name.', '.$first_name.'</option>';
                  echo $str;
            }
            mysql_free_result ($result);
?>
      </SELECT></td>
      <td><select tabindex="11" name="modify[]" multiple size="10"onchange="changeList(this, this.form);">
<?php
      ////////////////////Read//////////////////////////
            $query = "SELECT id, last_name, first_name FROM user ORDER BY last_name";
            $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
            //////////////////Forbidden////////////////////
            while(list($id, $last_name, $first_name) = mysql_fetch_row($result))
            {
                  $str = '<option value="' . $id . '"';
                  // select current user's name
                  if($id == $_SESSION['uid']) {$str .= ' selected';}
                  $str .= '>'.$last_name.', '.$first_name.'</option>';
                  echo $str;
            }
            mysql_free_result ($result);
?>
      </SELECT></td>
      <td><select tabindex="12" name="admin[]" multiple size="10" onchange="changeList(this, this.form);">
<?php
      ////////////////////Read//////////////////////////
            $query = "SELECT id, last_name, first_name FROM user ORDER BY last_name";
            $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
            //////////////////Forbidden////////////////////
            while(list($id, $last_name, $first_name) = mysql_fetch_row($result))
            {
                  $str = '<option value="' . $id . '"';
                  // select current user's name
                  if($id == $_SESSION['uid']) {$str .= ' selected';}
                  $str .= '>'.$last_name.', '.$first_name.'</option>';
                  echo $str;
            }
            mysql_free_result ($result);
?>      </SELECT></td>
      
      </TR>
      </TABLE>
      <tr>
      <td colspan="4" align="center"><input tabindex=7 type="Submit" name="submit" value="Add Document"></td>
      </tr>
<?php      
            $query = "SELECT name, id FROM department ORDER BY name";
            $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
            while( list($dept_name, $dept_id) = mysql_fetch_row($result) )
            {            
                  if($dept_id == $current_user_dept)
                        echo "\n\t".'<input type="hidden" name="'. space_to_underscore($dept_name).'" value="1"> '."\n";
                  else
                        echo "\n\t".'<input type="hidden" name="'.space_to_underscore($dept_name).'" value="0"> '."\n";
            }
            echo "\n\t".'<input type="hidden" name="default_Setting" value="0"> '."\n";
            mysql_free_result ($result);
?>
      </form>
      </table>
      </center>
<?php
draw_footer();
}
else //submited form
{
      for($khoa = 0; $khoa<1; $khoa++)// change this to 100 if you want to add 100 of the same files automatically.  For debuging purpose only
      {
            if ($GLOBALS['CONFIG']['authorization'] == 'On')
                  $lpublishable = '0';
            else
                  $lpublishable= '1';
      $result_array = array();
      //get user's department
      $query ="SELECT user.department from user where user.id=$_SESSION[uid]";
      $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
      if(mysql_num_rows($result) != 1)
      {
            header('Location:error.php?ec=14');
            exit; //non-unique error
      }
      list($current_user_dept) = mysql_fetch_row($result);

      //can't upload empty file
      if ($_FILES['file']['size'] <= 0 )
      {
            header('Location:error.php?ec=11');
            exit;
      }

    // File too big?
    if($_FILES['file']['size'] >  $GLOBALS['CONFIG']['max_filesize'] )
    {
            header('Location:error.php?ec=25');
            exit;
      }
       
      // check file type.  refer to config.php to see which file types are allowed
      $allowedFile = 0;
      foreach($allowedFileTypes as $thistype)
      {
        if ($_FILES['file']['type'] == $thistype)
        {
            $allowedFile = 1;
            break;
        }
    }      
      // for non_allowed file types
      if (!isset($allowedFile))
      {
            header('Location:error.php?ec=13&last_message=MIMETYPE+failed+' . $_FILES['file']['type']);
            exit;
      }

        // Check to make sure the dir is available and writeable        
        if (!is_dir($GLOBALS['CONFIG']['dataDir']))
        {
                $last_message=$GLOBALS['CONFIG']['dataDir'] . ' missing!';
                header('Location:error.php?ec=23&last_message=' .$last_message);
                exit;
        }
        else
        {
                if (!is_writeable($GLOBALS['CONFIG']['dataDir']))
                {
                        $last_message='Folder Permissions Error: ' . $GLOBALS['CONFIG']['dataDir'] . ' not writeable!';
                        header('Location:error.php?ec=23&last_message=' .$last_message);
                        exit;
                }
        }
      // all checks completed, proceed!
      // INSERT file info into data table
      $query = "INSERT INTO data (status, category, owner, realname, created, description, department, comment, default_rights, publishable) VALUES(0, '" . addslashes($_REQUEST['category']) . "', '" . addslashes($_SESSION['uid']) . "', '" . addslashes($_FILES['file']['name']) . "', NOW(), '" . addslashes($_REQUEST['description']) . "','" . addslashes($current_user_dept) . "', '" . addslashes($_REQUEST['comment']) . "','" . addslashes($_REQUEST['default_Setting']) . "', $lpublishable )";
      $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
      
      // get id from INSERT operation
      $fileId = mysql_insert_id($GLOBALS['connection']);

      udf_add_file_insert($fileId);
      
      //Find out the owners' username to add to log
      $query = "SELECT username from user where id='$_SESSION[uid]'";
      $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
      list($username) = mysql_fetch_row($result);
      
      // Add a log entry
      $query = "INSERT INTO log (id,modified_on, modified_by, note, revision) VALUES ( '$fileId', NOW(), '" . addslashes($username) . "', 'Initial import', 'current')";
      $result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
      

      //Insert Department Rights into dept_perms
      $query = "SELECT name, id FROM department ORDER BY name";
      $result = mysql_query($query, $GLOBALS['connection']) or die("Error in query: $query. " . mysql_error() );
      while( list($dept_name, $id) = mysql_fetch_row($result) )
      {
      //echo "Dept is $dept_name";
            $query = "INSERT INTO dept_perms (fid, rights, dept_id) VALUES('$fileId', '" . addslashes($_REQUEST[space_to_underscore($dept_name)]) . "', '$id')";
            $result2 = mysql_query($query, $GLOBALS['connection']) or die("Error in query: $query. " . mysql_error() );
      }
      // Search for simular names in the two array (merge the array.  repetitions are deleted)
      // In case of repetitions, higher priority ones stay.  
      // Priority is in this order (admin, modify, read, view)
      $filedata = new FileData($fileId, $GLOBALS['connection'], $GLOBALS['database']);      

        if  (isset ($_REQUEST['admin']))
        {
              $result_array = advanceCombineArrays($_REQUEST['admin'], $filedata->ADMIN_RIGHT, $_REQUEST['modify'], $filedata->WRITE_RIGHT);
        }

        if (isset ($_REQUEST['read']))
        {
              $result_array = advanceCombineArrays($result_array, 'NULL', $_REQUEST['read'], $filedata->READ_RIGHT);
        }

        if (isset ($_REQUEST['view']))
        {
              $result_array = advanceCombineArrays($result_array, 'NULL', $_REQUEST['view'], $filedata->VIEW_RIGHT);
        }

        if (isset ($_REQUEST['forbidden']))
        {
              $result_array = advanceCombineArrays($result_array, 'NULL', $_REQUEST['forbidden'], $filedata->FORBIDDEN_RIGHT);
        }
      // INSERT user permissions - view
        for($i = 0; $i<sizeof($result_array); $i++)
      {
            $query = "INSERT INTO user_perms (fid, uid, rights) VALUES('$fileId', '".$result_array[$i][0]."','". $result_array[$i][1]."')";
            $result = mysql_query($query, $GLOBALS['connection']) or die("Error in query: $query" .mysql_error());;
      }

      // use id to generate a file name
      // save uploaded file with new name
      $newFileName = $fileId . '.dat';
      
      if($khoa==0)
      {
            if (!is_uploaded_file ($_FILES['file']['tmp_name']))
            {
                  header('Location: error.php?ec=18');
                  exit;
            }
            move_uploaded_file($_FILES['file']['tmp_name'], $GLOBALS['CONFIG']['dataDir'] . '/' . $newFileName);
      }
      else
            copy($GLOBALS['CONFIG']['dataDir'] . '/' . ($fileId-1) . '.dat', $GLOBALS['CONFIG']['dataDir'] . '/' . $newFileName);
      // back to main page
      $message = urlencode('Document successfully added');
      header('Location: out.php?last_message=' . $message);
      }
}
?>
<SCRIPT LANGUAGE="JavaScript">

    var index = 0;
    var index2 = 0;
    var begin_Authority;
    var end_Authority;
    var frm_main = document.main;
    var dept_drop_box = frm_main.dept_drop_box;
    //Find init position of Authority
    while(frm_main.elements[index].name != "forbidden")
    {       index++;        }
      index2 = index;         //continue the search from index to avoid unnessary iteration
      // Now index contains the position of the view radio button
    //Next search for the position of the admin radio button
    while(frm_main.elements[index2].name != "admin")
    {       index2++;       }
    //Now index2 contains the position of the admin radio button
    //Set the size of the array
    begin_Authority = index;
    end_Authority = index2;
/////////////////////////////Defining event-handling functions///////////////////////////////////////////////////////
    var num_of_authorities = 4;
    function showData()
      {
            alert(frm_main.elements["Information_Systems"].value);
            alert(frm_main.elements["Test"].value);
            alert(frm_main.elements["Toxicology"].value);
      }
      function test()
      {
            alert(frm_main.elements["default_Setting"].value);
      }
      
      //loadData(_selectedIndex) load department data array
      //loadData(_selectedIndes) will only load data at index=_selectedIndex-1 of the array since
      //since _selectedIndex=0 is the "Please choose a department" option
      //when _selectedIndex=0, all radio button will be cleared.  No department[] will be set
      function loadDeptData(_selectedIndex)
    {
        if(_selectedIndex > 0)  //does not load data for option 0
        {
              switch(departments[(_selectedIndex-1)].getRights())
              {
                    case -1:
                          frm_main.forbidden.checked = true;
                              deselectOthers("forbidden");
                              break;
                        case 0:
                        frm_main.none.checked = true;
                              deselectOthers("none");
                              break;
                        case 1:
                        frm_main.view.checked = true;
                              deselectOthers("view");
                        break;
                    case 2:
                              frm_main.read.checked = true;
                              deselectOthers("read");
                          break;
                    case 3:
                              frm_main.write.checked = true;
                        deselectOthers("write");
                        break;
                    case 4:
                              frm_main.admin.checked = true;
                              deselectOthers("admin");
                             break;                        
                        default: break;
                  }
          }
          else
          {
                  index = begin_Authority;
              while(index <= end_Authority)
              {
                        frm_main.elements[index++].checked = false;
              }
               }
    }
      
      //Deselect other button except the button with the name stored in selected_rb_name
      //Design to control the rights radio buttons
      function deselectOthers(selected_rb_name)
    {
            var index = begin_Authority;
        while(index <= end_Authority)
        {
                  if(frm_main.elements[index].name != selected_rb_name)
                 {
                  frm_main.elements[index].checked = false;
                 }
                  index++;
        }
    }
      
      function spTo_(string)
      {
            // Joe Jeskiewicz fix
            var pattern = / /g;
            return string.replace(pattern, "_");
      //      return string.replace(" ", "_");
      }
      
      function setData(selected_rb_name)
    {
            var index = 0;
            var current_selected_dept =  dept_drop_box.selectedIndex - 1;
            var current_dept = departments[current_selected_dept];
            deselectOthers(selected_rb_name);
            //set right into departments
            departments[current_selected_dept].setRights(frm_main.elements[selected_rb_name].value);
            //Since the All and Defualt department are abstractive departments, hidden fields do not exists for them.
            if(current_selected_dept-2 >= 0) // -1 from above and -2 now will set the first real field being 0
            {
                  //set department data into hidden field
                  frm_main.elements[spTo_( current_dept.getName() )].value = current_dept.getRights();            
            }
            departments[current_selected_dept].setFlag("true");
            if(  current_selected_dept == default_Setting_pos )  //for default user option
        {
              frm_main.elements['default_Setting'].value = frm_main.elements[selected_rb_name].value
              while (index< dept_drop_box.length)
            {
                  //do not need to set "All Department" and "Default Department"  they are only abstracts
                        if(departments[index].issetFlag() == false && index != all_Setting_pos && index != default_Setting_pos)
                {
                      //set right radio buton's value into all Department that is available on the database
                              departments[index].setRights(frm_main.elements[selected_rb_name].value);
                              //set right onto hidden valid hidden fields to communicate with php
                              frm_main.elements[spTo_(departments[index].getName())].value = frm_main.elements[selected_rb_name].value;
                        }
                index++;
            }
                  index = 0;
        }
            if( current_selected_dept == all_Setting_pos) //for all user option. linked with predefine value above.
            {
                  index = 0;
                  while(index < dept_drop_box.length)
                  {
                        if(index != default_Setting_pos && index != all_Setting_pos) //Don't set default and All
                        {
                              //All setting acts like the user actually setting the right for all the department. -->setFlag=true
                              departments[index].setFlag(true);
                              //Set rights into department array
                              departments[index].setRights(frm_main.elements[selected_rb_name].value );
                              //Set rights into hidden fields for php
                              frm_main.elements[spTo_(departments[index].getName())].value = frm_main.elements[selected_rb_name].value;
                        }
                        index++;
                  }
            }
      }
      function changeList(select_list, current_form)
      {
            var select_list_array = new Array();
            select_list_array[0] = current_form['view[]'];
            select_list_array[1] = current_form['read[]'];
            select_list_array[2] = current_form['modify[]'];
            select_list_array[3] = current_form['admin[]'];
            for( var i=0; i < select_list_array.length; i++)
            {
                  if(select_list_array[i] == select_list)
                  {
                        for(var j=0; j< select_list.options.length; j++)
                        {
                              if(select_list.options[j].selected)
                              {
                                    for(var k=0; k < i; k++)
                                    {
                                          select_list_array[k].options[j].selected=true;      
                                    }//end for
                                    current_form['forbidden[]'].options[j].selected=false;
                              }//end if
                              else
                              {
                                    for(var k=i+1; k < select_list_array.length; k++)
                                    {
                                          select_list_array[k].options[j].selected=false;
                                    }
                              }//end else
                        }//end for      
                  }//end if
            }//end for
      }
      function changeForbiddenList(select_list, current_form)
      {
            var select_list_array = new Array();
            select_list_array[0] = current_form['view[]'];
            select_list_array[1] = current_form['read[]'];
            select_list_array[2] = current_form['modify[]'];
            select_list_array[3] = current_form['admin[]'];
            for(var i=0; i < select_list.options.length; i++)
            {
                  if(select_list.options[i].selected==true)
                  {
                        for( var j=0; j < select_list_array.length; j++)
                        {
                              select_list_array[j].options[i].selected=false;      
                        }//end for
                  }
            } //end for
      }

</SCRIPT>
The search on database works fine seperate from this already existing code.
Any help would be great.
thanks in advance.
Brad


Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Your problem will be almost entirely within your markup. Create clean forms, then in your PHP, reference a field in one of the forms using isset(). If it fails, try a field in the other form using isset(). If that fails, then no form data was passed.
bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

Post by bradleyd »

thanks for the reply, not to sound like a idiot, but are you saying my forms are incorrect?This is what I added since I posted earlier. Am I on the right track?

Code: Select all

else //submited form
{
	if ($_POST["submit"] == "Add Document") {
	  for($khoa = 0; $khoa<1; $khoa++)// change this to 100 if you want to add 100 of the same files automatically.  For debuging purpose only
	  {
		if ($GLOBALS['CONFIG']['authorization'] == 'On')
			$lpublishable = '0';
		else
			$lpublishable= '1';
	$result_array = array();
	//get user's department
	$query ="SELECT user.department from user where user.id=$_SESSION[uid]";
	$result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
	if(mysql_num_rows($result) != 1)
	{
		header('Location:error.php?ec=14');
		exit; //non-unique error
	}
	list($current_user_dept) = mysql_fetch_row($result);

	//can't upload empty file
	if ($_FILES['file']['size'] <= 0 )
	{ 
		header('Location:error.php?ec=11'); 
		exit; 
	}

    // File too big?
    if($_FILES['file']['size'] >  $GLOBALS['CONFIG']['max_filesize'] ) 
    {
		header('Location:error.php?ec=25'); 
		exit; 
	}
        
	// check file type.  refer to config.php to see which file types are allowed
	$allowedFile = 0;
	foreach($allowedFileTypes as $thistype)
	{
        if ($_FILES['file']['type'] == $thistype) 
        { 
            $allowedFile = 1;
            break; 
        } 
    }	
	// for non_allowed file types
	if (!isset($allowedFile)) 
	{ 
		header('Location:error.php?ec=13&last_message=MIMETYPE+failed+' . $_FILES['file']['type']); 
		exit; 
	}

        // Check to make sure the dir is available and writeable        
        if (!is_dir($GLOBALS['CONFIG']['dataDir']))
        {
                $last_message=$GLOBALS['CONFIG']['dataDir'] . ' missing!';
                header('Location:error.php?ec=23&last_message=' .$last_message);
                exit;
        }
        else
        {
                if (!is_writeable($GLOBALS['CONFIG']['dataDir']))
                {
                        $last_message='Folder Permissions Error: ' . $GLOBALS['CONFIG']['dataDir'] . ' not writeable!';
                        header('Location:error.php?ec=23&last_message=' .$last_message);
                        exit;
                }
        }
		if (!isset($_POST['submitted'])) {
	      if ($search) {
            $query = "SELECT * FROM TAXPM INNER JOIN ADDR ON TAXPM.TAXROLL_PIN=ADDR.ADDR_PIN  WHERE TAXROLL_PIN='$search' ";
            $result= mysql_query ($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());
	        if ($result) {
	           while ($r = mysql_fetch_array($result)) { // Begin while
	                $parcel = $r["TAXROLL_PIN"];
					$last = $r["OWN_LNAME"];
					$first = $r["OWN_FNAME1"];
					$first1 = $r["OWN_FNAME2"];
					$addr = $r["ADDR_STNUMF"];
					$addr1 = $r["ADDR_STNAME"];
					$addr2 = $r["ADDR_STDIR"];
					$addr3 = $r["ADDR_CITY"];
					$addr4 = $r["ADDR_ZIP"];
        		}// end while
      }//end if result
     }
			}
			
  }
	// all checks completed, proceed!
I hope I posted that right.
Thanks.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Something like that, yeah. Both forms have a submit button element named 'Submit'. How are you supposed to know which one was clicked when they are named the same?
bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

Post by bradleyd »

that is what I was thinking but unsure how to differ between two?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

We've just had this discussion about determining which form was submitted
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

bradleyd wrote:that is what I was thinking but unsure how to differ between two?
form 1:

Code: Select all

<input type="submit" name="Submit_Form1" value="Send this form (1)" />
form 2:

Code: Select all

<input type="submit" name="Submit_Form2" value="Send this form (2)" />
Processor.php:

Code: Select all

<?php
if (isset($_POST['Submit_Form1'])) // Or you could check for a field inside the form that is unique
{
  // do something
}
elseif (isset($_POST['Submit_Form2']))
{
  // Do something else
}
?>
There are a lot of other ways to do this. Play around with it a little bit and see what you can come up with.
bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

Post by bradleyd »

ok I will, thanks again.
bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

Post by bradleyd »

ok I turned on error reporting in php.ini and when the page loads it tells me:
Notice: Undefined variable: search in /var/www/html/opendocman/add2.php on line 43
line 43 contains this:

Code: Select all

if ($search)  {
			$query = "SELECT * FROM TAXPM INNER JOIN ADDR ON TAXPM.TAXROLL_PIN=ADDR.ADDR_PIN  WHERE TAXROLL_PIN='$search' ";
The search variable is the one on the new form I added.

Code: Select all

<form  name="parcel" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      <table width=90% align=right>
      <tr>
      <td width="10%"><font size="2" face="Geneva, Arial, Helvetica, sans-serif"><strong>search for:</strong></font></td>
      <td width="16%"><input type="text" name='search' size=25 maxlength=155></td>
      <TD width="74%"><input name="newsubmit" type="submit" value="Find It"></TD>

      </tr>
I am not really sure why this variable is undefined.
Thanks in advance.
bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

Post by bradleyd »

read somewhere that E_NOTICE should not be on, When I turned on errors E_NOTICE was on, if I turn it off I do not get the undefined variable., but is that the real problem?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_POST['search']

make sure you pass that through mysql_real_escape_string(), at minimum.

Also, don't use PHP_SELF, and header() based redirection is supposed to be done with full URLs, not partial/relative.
bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

Post by bradleyd »

thanks,
added

Code: Select all

if ($_POST['search'] )  {
before query. I commented out query and put

Code: Select all

if ($_POST['search'] )  {
echo $search;
}
In it's place to see if it could read the value in the search text box. It did not. Any ideas why the search text box variable is not callable?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$search still won't exist until you set it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The way you are handling your conditional is throwing the error. Lowering the error reporting level does not make it go away, it just reduces the likelihood of seeing lower level warnings/notices/errors.

You can use your code the way it is as long as you do something like this ahead of time:

Code: Select all

<?php
$search = false; // or null or 0

if (!empty($_POST['search']))
{
    $search = $_POST['search'];
}

if ($search) // yadda yadda
?>
FYI, an undefined variable is exactly what is says it is... a variable that has no definition (meaning it is null or not set to anything).
bradleyd
Forum Newbie
Posts: 16
Joined: Mon Apr 30, 2007 1:12 pm

Post by bradleyd »

that worked! thank you. I was going to throw the web server out of the window. Thanks you to everyone who answered and gave help.
Post Reply