Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

encapsulation 1

Status
Not open for further replies.

Bertiethedog

Programmer
Feb 8, 2007
118
GB
Hi

Obviously I am not stuck as I could go back to my original method of calling a completely seperate file (updatefuel.php)

It would be nice if I could encapsulate the code with the calling form as neither are very big.

At the mo I get error 404

Richard


Code:
<th height="206" scope="row"><form name="form4" id="form4" method="post" action="updatefuel()">


Code:
function updatefuel()
{
die('testing');
}
 
the action in your form tag won't work. the action attribute means the web address (or javascript function sometimes) to which the browser should send the form output.

what you need to do is have a hidden field in the form that specifies the action

Code:
<input type="hidden" name="action" value="updatefuel" />

then set the action attribute to your receiving script.

in your receiving script do something like this

Code:
$action = isset($_GET['action']) ? trim($_GET['action']) : '';
switch ($action){
  
  case 'updatefuel':
   //do something
   break;
  case 'somethingelse':
   //do something else
   break;
  default: 
   //do the default action where no action is specified
}
 
thanks I have loads of simple forms with simple actions & its handy if they are all in the same file


Richard
 
so i would have the form displayed as part of a function called displayForm(). then make the default action to call displayForm().

i use this method to power all my websites. each of my sites is driven off a single page (a despatcher) that decides what to do display depending on what the user asks for, what's in the session cache etc. it's a very secure method of programming.

it need not conflict with SEO, through the use of mod_rewrite or its IIS equivalent.
 
lets see if i have this right.

create the form in a variable $output

the default action is Print $output and show the complete form. Then say by changing a variable say $action to 1 and rerunning the form it would say do some calculations instead.

I already do something similar for my invoice processing.

The $action could be a session variable initialised before the procedure is run


regards

richard







 
you don't need to have it as a string variable, but no harm either.

 
Sorry I havn't replied earlier, but its been a bit busy. I am also trying to recover from an illness as well as keeping my contract.

Thanks to jPadie, I will try out this technique as soon as I get half an hour to have a play

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top