Jump to content

very simple cms form problem [MODIFIED and formatted :)]


amplexus

Recommended Posts

Hi,

I'm creating a website, and want to have text on a portion of each page be editable by a non-tech, average user.  I've created a form, and I've got it to work. I'm using .txt files.

 

what I've tried to do is create one page that has all of the pages' editable areas on it, each one displaying the current text, and a submit button to make the changes live.  in the code, the php to generate the forms is after each of the text lines beginning with "Edit copy".

 

Problem:  when you click any of the submit buttons, all of the areas update.  is it that i need to make each separate form code have a different input name?

 

here;s my code, formatted to make it easier to read, since I was completely exhausted before.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
Edit copy for Homepage to appear as you want on the website, then click "update"
<?
if($_POST['Submit']){
$open = fopen("index.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "<br /><br /><br />File updated to:<br /><br /><br />";
?>
<a href="../index.php">View Live Results</a><br /><br /><br />
<?
$file = file("index.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("index.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


Edit copy for About Us page to appear as you want on the website, then click "update"
<?
if($_POST['Submit']){
$open = fopen("about.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "<br /><br /><br />File updated to:<br /><br /><br />";
?>
<a href="../about.php">View Live Results</a><br /><br /><br />
<?
$file = file("about.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("about.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


Edit copy for Rental Property Page to appear as you want on the website, then click "update"
<?
if($_POST['Submit']){
$open = fopen("rental.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "<br /><br /><br />File updated to:<br /><br /><br />";
?>
<a href="../rental.php">View Live Results</a><br /><br /><br />
<?
$file = file("rental.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("rental.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


Edit copy for Crew to appear as you want on the website, then click "update"
<?
if($_POST['Submit']){
$open = fopen("crew.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "<br /><br /><br />File updated to:<br /><br /><br />";
?>
<a href="../crew.php">View Live Results</a><br /><br /><br />
<?
$file = file("crew.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("crew.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


Edit copy for Order Lobsters to appear as you want on the website, then click "update"
<?
if($_POST['Submit']){
$open = fopen("order.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "<br /><br /><br />File updated to:<br /><br /><br />";
?>
<a href="../order.php">View Live Results</a><br /><br /><br />
<?
$file = file("order.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("order.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>

</body>
</html>

what's wrong?

Link to comment
Share on other sites

you can either use hidden input together with if statements as a token to diffreciate which form was set when the submit battom was pressed.

 

<input name="hidden" type="hidden" value="hidden" />

 

if(isset($_post['hidden'])){

do something

}

 

or change the names of the submit batton to something specific and use it as th token to do the above job.

 

 

<input name="Kiwanyed" type="submit" value="Kiwanyed" />

 

if(isset($_post['kiwanyed'])){

do something

}

 

Link to comment
Share on other sites

[code}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>


Edit copy for Homepage to appear as you want on the website, then click "update"
	<?
		if($_POST['home']){
		$open = fopen("index.txt","w+");
		$text = $_POST['update'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>

<a href="../index.php">View Live Results</a><br />
<br />
<br />

	<?
		$file = file("index.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("index.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"home\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"home\" type=\"submit\" value=\"Update\" />\n
		</form>";
		}
	?>





Edit copy for About Us page to appear as you want on the website, then click "update"
	<?
		if($_POST['Submit']){
		$open = fopen("about.txt","w+");
		$text = $_POST['update'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../about.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("about.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("about.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
		</form>";
		}
	?>





Edit copy for Rental Property Page to appear as you want on the website, then click "update"
	<?
		if($_POST['Submit']){
		$open = fopen("rental.txt","w+");
		$text = $_POST['update'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../rental.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("rental.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("rental.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
		</form>";
		}
	?>



Edit copy for Crew to appear as you want on the website, then click "update"
	<?
		if($_POST['Submit']){
		$open = fopen("crew.txt","w+");
		$text = $_POST['update'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../crew.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("crew.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("crew.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
		</form>";
		}
	?>





Edit copy for Order Lobsters to appear as you want on the website, then click "update"
	<?
		if($_POST['Submit']){
		$open = fopen("order.txt","w+");
		$text = $_POST['update'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../order.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("order.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("order.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
		</form>";
		}
	?>
</body>
</html>

Link to comment
Share on other sites

so, In the last bit you can see (I hope)that I've changed the first form to have a name of "home" and adjusted the $_POST value to "home" as well.  this has the effect of changing just the one value, and leaving the other forms intact.  however, it also seems to change the .txt value to a blank.  I'm thinking that the fwrite value needs to be changed, am I barking up the right tree here?

 

Link to comment
Share on other sites

Each if($_POST['Submit']) should have a different unique name so it knows which one you're actually wanting to run. Name them Submit_index, Submit_about, Submit_rentals, you get the deal. You'll also need to change the name of each submit button to match accordingly.

 

Is it changing all the text files into blank ones or just the one you hit submit?

Link to comment
Share on other sites

and so I've got this, and thank you for the changing names idea, I also figured out that I needed to change the textarea name. 

 

 

it seems to be working okay...

<body>


Edit copy for Homepage to appear as you want on the website, then click "update"
	<?
		if($_POST['home']){
		$open = fopen("index.txt","w+");
		$text = $_POST['hometext'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>

<a href="../index.php">View Live Results</a><br />
<br />
<br />

	<?
		$file = file("index.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("index.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"hometext\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"home\" type=\"submit\" value=\"Update Homepage\" />\n
		</form>";
		}
	?>





Edit copy for About Us page to appear as you want on the website, then click "update"
	<?
		if($_POST['about']){
		$open = fopen("about.txt","w+");
		$text = $_POST['about_text'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../about.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("about.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("about.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"about_text\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"about\" type=\"submit\" value=\"Update about us\" />\n
		</form>";
		}
	?>





Edit copy for Rental Property Page to appear as you want on the website, then click "update"
	<?
		if($_POST['Stental']){
		$open = fopen("rental.txt","w+");
		$text = $_POST['rental_text'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../rental.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("rental.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("rental.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"tental_text\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"rental\" type=\"submit\" value=\"Update Rental Text\" />\n
		</form>";
		}
	?>



Edit copy for Crew to appear as you want on the website, then click "update"
	<?
		if($_POST['crew']){
		$open = fopen("crew.txt","w+");
		$text = $_POST['crew_text'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../crew.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("crew.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("crew.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"crew_text\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"crew\" type=\"submit\" value=\"Update Crew Text\" />\n
		</form>";
		}
	?>





Edit copy for Order Lobsters to appear as you want on the website, then click "update"
	<?
		if($_POST['order']){
		$open = fopen("order.txt","w+");
		$text = $_POST['order_text'];
		fwrite($open, $text);
		fclose($open);
		echo "<br /><br /><br />File updated to:<br /><br /><br />"; 
	?>
<a href="../order.php">View Live Results</a><br />
<br />
<br />
	<?
		$file = file("order.txt");
		foreach($file as $text) {
		echo $text."<br />";
		}
		}else{
		$file = file("order.txt");
		echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
		echo "<textarea Name=\"order_text\" cols=\"50\" rows=\"10\">";
		foreach($file as $text) {
		echo $text;
		} 
		echo "</textarea>";
		echo "<input name=\"order\" type=\"submit\" value=\"Update Order Page Text\" />\n
		</form>";
		}
	?>

 

which seems to be working fine.

 

if you're so inclined, do you see any problems?  I know about security,and will be adding a passcode protection before going "live"

 

 

Link to comment
Share on other sites

  • 1 month later...

okay, have to revive this thread.  what I've discovered when I gave this to the client is that they LOVE to use contractions in their copy. 

 

Every time they put an apostrophe, PHP puts a backslash, so it's becomes it\'s.

 

is there a way to tell php that this is a .txt file it is writing to? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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