Pioneer Skin
Login  ::  Register
Thursday, February 09, 2012
 
- - - - - - - - Sponsorship Advertisement Area - - - - Thank you to our Sponsors - - - - - - - - -
New Horizons Computer Learning Centers
WGD Discussion Forum
SearchForum Home
     
  Web Design  Programming  Making reusable...
 Making reusable php code
 
 6/14/2007 5:52:54 PM
therustycook
15 posts


Making reusable php code
OK here is the scoop.  I am working at rewriting a website that I have at work for doing LDAP stuff.  I have some queries that I put together and people liked them and want a full blown site with much more stuff.  I moved the LDAP calls to functions so that I can move them from one web page to another.  I would actually like to put them into stand-alone php files and then just call them from a web page by passing variables to the php code from the initial page.  I want to do this so that I can write the LDAP query logic once and use it over and over and for multiple LDAP trees. 

I was looking at the lesson from this months meeting and see how to call the php file from a form but am wondering how I pass multiple variables to the php code?  Also, can I pass the info from some php code in the main page to the other file so that I can use some additional logic in the main page when I get the other information back? 
 6/15/2007 4:39:58 PM
tgoodson
4 posts
www.omega-link.com


Re: Making reusable php code

If you are using a form post, then everything that you need is done. Every "input" value will be passed to the script when you click the submit button. If you want to send data that isn't entered by the user, then look at the input type "hidden".  below, I've included two files that should give you the idea.

** Tom **

multiform.php:

<html><?php
$dv = "<first name>";
if (isset($_GET['User'])) $dv=$_GET['User'];
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="phpclass.css" />
</head>

<body>

<form method="post" action="multi.php" enctype="multipart/form-data">
  <label id="Label1">What is your name? </label>
  <input name="UserName" type="text" value="<?php echo $dv;?>" />
  <input name="LastName" type="text" value="last name" />
  <br /><br />
  <input name="Submit1" type="submit" value="submit" />
  <input name="Reset1" type="reset" value="reset" />
  <?php echo "This is PHP!"; ?>
</form>

</body></html>

multi.php

<?php
echo "Hello, ".$_POST['FirstName']." ".$_POST['LastName']."!";
?>

 6/15/2007 4:43:56 PM
tgoodson
4 posts
www.omega-link.com


Re: Making reusable php code

Of course, I might have missed the entire point in that last post.  In your case, it might be well worthwhile to simply put your functions into one or more pure php files and to do an

<?php
include("filename.php");
?>

** Tom **

 6/15/2007 4:51:59 PM
tgoodson
4 posts
www.omega-link.com


Re: Making reusable php code

Opps!  change that "UserName" to "FirstName" in multiform.php

** Tom **

  Web Design  Programming  Making reusable...
Copyright 2007-2008 by WGD Forum :: Designed by ZapWebDesign.com