Page 1 of 1

Include script won't process form

Posted: Mon May 10, 2010 5:28 pm
by pizzipie
10 May 2010 3:13 PM

I am working on an accounts program in which I want to set up a new account. I can't make it work the way I want. The form contained in the 'include' file will not process.
Please help.

Thanks in advance

Rick P
=================================================================================================================================
Structure is briefly as follows:

A. ShowCompany.php Shows company information to be processed or opportunity to create a new account.
In which has: Form in which: action='ProcessAccountData.php'
submit choices are: All 4 choices name='operation' 1. No Change/Exit 2. Revise This Account 3. New Account 4. Delete This Account

B. ProcessAccountData.php ........... I use switch to process $_POST from ShowCompany.php.

switch ($_POST['operation']) {
.
.
.
===>> case "New Account":
include "NewAccount.php"; // returns here without ever having stopped to receive submits see code below

code here to create $query and input to MySql
break;

default:
exit("Bye Bye From switch");
break;
}

C. NewAccount.php Full code below: If I un-comment the "require files" and run this as a stand alone script it works fine.
If I try to call it from the switch in ProcessAccountData.php ("require" files can't be used or you
get errors) as below, the code returns to the switch statement without processing the submit code.

=======================================================================================================================
NewAccount.php Code

Code: Select all

<html>

<head><title>Account Companies</title></head>

<body>

<?php


 // require "db-accts.inc";               When using  as stand alone script must un-comment                 

 // require "functions.inc";              these to avoid duplicate declaration errors. 
 //require "functions-accounts.inc";
 
  if(!isset($pass)) {                      // avoiding errors when $_SERVER[PHP_SELF] runs itself again

        $cxn = mysqli_connect($hostname,$username,$password,$database)
         or die ("couldn't connect to server");
          
        $labels=array_combine(getTableFields($cxn, $table), $colhead); //  getTableFields in functions.inc
        listArray($labels);        // listArray in functions-accounts.inc
 }
 
 $pass='yes';

	echo "<form action='$_SERVER[PHP_SELF]' method='POST'>

              <table>";
 

        foreach($labels as $field=>$label) {
  
        if($field=="Hints")               // create 'text area' rather than text line
               
                echo "<tr><td style='text-align: left;
                        font-weight: bold'>$label</td>
                        <td><textarea name='$field'
                        rows='4' cols='65' wrap='wrap'> $row[$field]
                        </textarea>
                        </td></tr> ";                      
        else    
        
       if($field=="IDno") continue;     // IDno must be void in new account so don't show it
        
        else            

                echo "<tr>

                        <td style='text-align: left; 

                          font-weight: bold'>$label</td>

                        <td><input type='text' name='$field' 

                        value='$row[$field]' size='65' 

                        maxlength='65'> 

                        </td></tr>  ";

  }

        echo "<tr><td>&nbsp;</td>
                 <td style='text-align: left'>

           <input type='submit'  name='go' value='Never Mind, Abort'>";  
       echo "&nbsp&nbsp&nbsp<input type='submit'  name='go' value='Store New Account'>";              

       echo "</td></tr></table>

        </div>

        </form>";
       
       $action=$_POST['go'];     
       $StoredArray=($_POST);   // these two lines to be used to generate $query and pass to MySql
/*       
       sleep(5);
       echo "GO<br>", $_POST['go'], "<br>";         debugging stuff
        
     listArray($_POST); 
     echo "Stored Array <br>";
      $StoredArray=($_POST);
      listArray($StoredArray); 
      
 exit("Bye from Newaccount");     
*/      
 ?>



</body></html>

Re: Include script won't process form

Posted: Mon May 10, 2010 10:51 pm
by yacahuma
I am going to suggest something to you, and some people in this forum may disagree with me. The beauty of web programming is the simplicity of html. Many try to hide the simplicity with things like the one you are doing right now. You may think you are gaining something with putting all the actions in one page, but you are not. Just keep you pages simple And use as less php as possible for your pages. You will find that projects are easier, faster and more importantly simple. So basically, just keep all your actions in their corresponding pages and forget about including all the actions in one page.

Re: Include script won't process form

Posted: Tue May 11, 2010 1:02 pm
by pizzipie
SOLVED, I think. Thanks Yacahuma. I agree totally with you. The task was finding a simple solution.

I think I found what I was looking for: Here is the code. It is certainly simple.

Code: Select all

   NOTE: I don't know how to use this thing; trying to simplify reading code as suggested elsewhere in forum.

<?php

  /* Program: Switch the 'action' field in an HTML form dynamically

   * Desc:    By using multiple submit buttons

              switch to selective php scripts.

   *          Uses Javascript

   */

?>


<html>

<head><title>Account Companies</title></head>

<body>


<!--  =========================================  Javascript Dynamic Action Switch ================= -->

 <SCRIPT language="JavaScript">
function OnSubmitForm()
{
  if(document.pressed == 'Insert')
  {
   document.myform.action ="AccountsFrontEnd.php"; 
  }
  else
  if(document.pressed == 'Update')
  {
    document.myform.action ="ExitProgram.php";
  }
  return true;
}
</SCRIPT>

<FORM name="myform" onSubmit="return OnSubmitForm();">

<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">

<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">

</FORM> 


</body>
</html>

]