MindPalette Discussion Forum

Using php variables in .txt file

MindPalette tutorials and scripts

Using php variables in .txt file

Postby DirtyPete on 10/16/2008 @ 13:42

Hi there,
Here goes...
I am trying to use the random text 1.1 script to generate content for my site and it is working pretty well. I am just running into one minor issue. My script is currently running on http://contentgenerator.automopedia.org , the goal is to allow users to input information about a car dealership into a form, ideally my page will then return basic content written about the dealership.
Here is my index page code with the form:
Code: Select all
<?php
$dealer = $_POST["dealer"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$phone = $_POST["phone"];
$brand = $_POST["brand"];
$model1 = $_POST["model1"];
$model2 = $_POST["model2"];
$model3 = $_POST["model3"];
$model4 = $_POST["model4"];
$model5 = $_POST["model5"];
$domain = $_POST["domain"];
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<head>
<title>Content Generator</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Dealer Name:<br /><input type="text" size="12" maxlength="48" name="dealer"value="Automaster Honda"><br />
Address:<br /><input type="text" size="12" maxlength="48" name="address"value="20 Shelburne Rd"><br />
City:<br /><input type="text" size="12" maxlength="48" name="city" value="Burlington"><br />
State:<br /><input type="text" size="12" maxlength="48" name="state"value="VT"><br />
Phone:<br /><input type="text" size="12" maxlength="48" name="phone"value="888-222-5555"><br />
Brand:<br /><input type="text" size="12" maxlength="48" name="brand"value="Honda"><br />
Model 1:<br /><input type="text" size="12" maxlength="48" name="model1"value="Civic"><br />
Model 2:<br /><input type="text" size="12" maxlength="48" name="model2"value="Accord"><br />
Model 3:<br /><input type="text" size="12" maxlength="48" name="model3"value="Pilot"><br />
Model 4:<br /><input type="text" size="12" maxlength="48" name="model4"value="Ridgeline"><br />
Model 5:<br /><input type="text" size="12" maxlength="48" name="model5"value="Element"><br />
Dealer Domain:<br /><input type="text" size="12" maxlength="48" name="domain" value="automaster.com"><br />
<input type="submit" value="submit" name="submit">
</form>


<?
} else {
echo "Welcome to ".$dealer." located at ".$address." in ".$city.", ".$state.".<br />";
echo "----------------------------Index--------------------<br />";
include_once("GetRandomText.php");
$MPTextFile = "indexintro.php";
$MPSepString = "*divider*";
$MPTextToHTML = false;
MPPrintRandomText($MPTextFile, $MPSepString, $MPTextToHTML);
}
?>


I would like the txt file to contain variables from the form which would be converted to their respected values. I have changed the .txt file to indexintro.php, and reference my variables within with the following code:

Code: Select all
*divider*<? echo "<h1 style="font-size: 10pt">
Visit ".$dealer." Today for Huge Savings on a New or Used ".$brand." in ".$city."
</h1>
<p>
At our greater ".$city." new and used ".$brand." dealership your satisfaction is our primary concern. With a knowledgeable sales team, large inventory and everyday low prices, ".$dealer." is the first and last place you will need to shop for a new or used car by ".$brand.". We are dedicated to exceeding the expectations of each individual that walks through the dealership's door.  The staff at ".$dealer." is proud to serve the community of ".$city." with ".$brand." vehicles and would  like to have the opportunity to earn your business.  We are always available to answer your questions and can easily be contacted at ".$phone.".
</p>" ?>
*divider* <?php echo "<h1 style="font-size: 10pt">Shop at ".$dealer." For a Variety of New and Used  ".$brand." Cars in ".$city."</h1>
<p>
When you visit ".$dealer." you will experience the world class service of a knowledgeable and experienced staff.  We are committed to your satisfaction and strive to exceed our customers' expectations. We are the greater <strong>".$city." ".$brand." dealer</strong> with the inventory and price to get you into your dream car today. Set up a test drive by contacting our friendly sales staff at ".$phone." or submitting a short form on our inventory details pages.
</p>


If you use the form on http://contentgenerator.automopedia.org, you will notice that it returns the variable names instead of the variable's value. I am a relative php n00b, how can I fix this? Sorry if this is unclear, more than happy to answer questions.
DirtyPete
 
Posts: 1
Joined: 10/16/2008 @ 13:28

Re: Using php variables in .txt file

Postby Nate Baldwin on 10/20/2008 @ 15:53

Hi Pete,

Wish I could be more helpful, but it doesn't sound like the random text script will doing what you're hoping. Looks like you need more of a database or XML file to store the form submissions, then a template to load the data into? Not something I really have a pre-made script for right now, sorry.
Nate Baldwin
Site Admin
 
Posts: 3724
Joined: 04/25/2003 @ 19:05


Return to Tutorials and Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron