amplexus Posted July 20, 2012 Share Posted July 20, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/ Share on other sites More sharing options...
hakimserwa Posted July 20, 2012 Share Posted July 20, 2012 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 } Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1362980 Share on other sites More sharing options...
Donald. Posted July 20, 2012 Share Posted July 20, 2012 This is not what Pikachu2000 meant when he said to parse it with the code tags and formatted it properly. You also need to indent it so it flows easily when reading what it does. Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1362981 Share on other sites More sharing options...
amplexus Posted July 20, 2012 Author Share Posted July 20, 2012 [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> Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1362990 Share on other sites More sharing options...
amplexus Posted July 20, 2012 Author Share Posted July 20, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1362994 Share on other sites More sharing options...
Donald. Posted July 20, 2012 Share Posted July 20, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1362995 Share on other sites More sharing options...
amplexus Posted July 20, 2012 Author Share Posted July 20, 2012 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" Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1362996 Share on other sites More sharing options...
amplexus Posted September 12, 2012 Author Share Posted September 12, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1377155 Share on other sites More sharing options...
Pikachu2000 Posted September 12, 2012 Share Posted September 12, 2012 So magic_quotes_gpc must be on, then? Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1377160 Share on other sites More sharing options...
amplexus Posted September 12, 2012 Author Share Posted September 12, 2012 the site is hosted by Godaddy. is there a way to turn something like that off? Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1377192 Share on other sites More sharing options...
Christian F. Posted September 12, 2012 Share Posted September 12, 2012 Any host running with Magic Quotes still is extremely outdated, and as such I really recommend you to change hosts. (Not to mention all the other reasons, SOPA/IPROTECT being one of them.) Quote Link to comment https://forums.phpfreaks.com/topic/265982-very-simple-cms-form-problem-modified-and-formatted/#findComment-1377338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.