Jump to content

Call form objects outside the form tags


Darkmatter5

Recommended Posts

Can you call the value of a textbox from outside the form tags?  I have a form with a textbox inside it and a PHP script farther down the page, outside the form tag and I am trying to get the value typed into the textbox to display something.  But it's not working as if the textbox can't be found.

Link to comment
https://forums.phpfreaks.com/topic/127453-call-form-objects-outside-the-form-tags/
Share on other sites

I've gone and modified things a bit, but it's still not working.

 

<table width="304" border="0" cellpadding="2" cellspacing="1">
  <form>
  <th colspan="2" class="style1" align="center">CABINET MAINTENANCE</th>
  <tr>          
    <td class="style2" align="center" valign="top">
    <fieldset class="text_boxes"><legend>ADD A CABINET</legend>
    <table width="300" border="0" cellpadding="2" cellspacing="1">
      <tr>
        <td width="70" class="required_text" align="left">Name</td>
        <td width="230"><input name="cab_name" type="text" class="text_boxes" align="left"></td>
      </tr>
      <tr>
        <td align="left">Description</td>
        <td><input name="cab_description" type="text" class="text_boxes" align="left"></td>
      </tr>
    </table>
    </fieldset>
    <fieldset class="text_boxes"><legend>EDIT A CABINET</legend>
    <table width="300" border="0" cellpadding="2" cellspacing="1">
      <?php
        include 'library/config.inc.php';
        $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
        mysql_select_db($dbnamemain);
                      
        $query="SELECT cabinet_id, cab_name, cab_description
            FROM cabinets
            ORDER BY cab_name ASC";
        $result=mysql_query($query) or die ($query. '<br>' .mysql_error());
        while(list($cabinet_id, $cab_name, $cab_description)=mysql_fetch_array($result, MYSQL_NUM)) {
        if(empty($cab_description)) { $cabinet=$cab_name; }
        else { $cabinet=$cab_name. ": " .$cab_description; }
        echo "<tr>
          <td width='200' align='left'>" .substr($cabinet,0,100). "</td>
          <td width='100' align='center'>edit | <a href='javascript:delCabinet($cabinet_id,$cab_name);'>delete</a></td>
          </tr>";
        }
                      
        mysql_close($conn);
      ?>
    </table>
    </fieldset>
    </td>          
  </tr>
  <tr>
    <td class="text_boxes" align="left" valign="top">Submission status: <?php $ec->save_cabinet(); ?></td>
        </tr>
        <tr>
          <td class="style2" align="center">
            <input name="save_cabinet" type="submit" class="button" value="Submit Cabinet Data" />
            <input type="reset" class="button" value="Clear form" />
          </td>
    </tr>
  </form>
</table>

 

Here's the function "save_cabinet()"

function save_cabinet() {
            include 'library/config.inc.php';
            $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
            mysql_select_db($dbnamemain);
            
            if(isset($_POST['save_cabinet'])) {
                $name=$_POST['cab_name'];
                $description=$_POST['cab_description'];
                $creator=$_SESSION['member_id'];
                
                mysql_query("INSERT
                             INTO cabinets
                             (cab_name, cab_description, cab_creator)".
                             " VALUES ('$name', '$description', '$creator')
                             ") or die(mysql_error());
                echo "Cabinet '$name' added";
            }            
            
            mysql_close($conn);
        }

 

Please help me figure out why nothing is being processed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.