perthmetro Posted June 25, 2008 Share Posted June 25, 2008 As it is now when I click on submit the form goes blank and the form page is renamed from whatever.php to whatever.php# I have no php knowledge whatsoever, A friend made this for me and now he's gone on holidays - thanks for your help, the script is for a cms for a stylesheet - i'll post the whole script if i can fix this prob. -cheers Pete How can I 1. stop the form from going blank 2. keep the values I have previously submitted (they get written to a text file) in the form here is the form <?php //SITE BACKGROUND $bg = $_POST['bg']; //HEADER BORDER $hdrbdr = $_POST['hdrbdr']; //HEADER BACKGROUND $hdrbg = $_POST['hdrbg']; //HTML CODE - THIS IS THE CODE FOR THE HTML PAGE $html = file_get_contents("html.txt"); //IF FORM IS SUBMITED if($_POST) { $fp = fopen('bg.txt', 'w+'); fwrite($fp, $bg); fclose($fp); $fp = fopen('hdrbdr.txt', 'w+'); fwrite($fp, $hdrbdr); fclose($fp); $fp = fopen('hdrbg.txt', 'w+'); fwrite($fp, $hdrbg); fclose($fp); } else echo ($html); ?> Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/ Share on other sites More sharing options...
Jabop Posted June 25, 2008 Share Posted June 25, 2008 What is trying to be done here... Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-574326 Share on other sites More sharing options...
perthmetro Posted June 25, 2008 Author Share Posted June 25, 2008 Everything works fine except the problem I wrote above. The script simply gets the input values and writes them to their respective text files i then use the text files for other stuff Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-574327 Share on other sites More sharing options...
perthmetro Posted June 25, 2008 Author Share Posted June 25, 2008 I was thinking the # that gets appended to the filename may have something to do with it? Could that be the problem, if so how do i fix it? Thanks. Pete Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-574359 Share on other sites More sharing options...
perthmetro Posted June 25, 2008 Author Share Posted June 25, 2008 whoops sorry... here is the form... <form id="colors" name="colors" method="post" action="#"> <p>site background: <input name="bg" type ="text" id="bg" /></p> <p>header border: <input name="hdrbdr" type ="text" id="hdrbdr" /></p> <p>header background: <input name="hdrbg" type ="text" id="hdrbg" /></p> <p><input type="submit" name="Submit" value="Submit" /></p> </form> I deleted the # in the --- action="#" --- but it made no difference Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-574369 Share on other sites More sharing options...
perthmetro Posted June 26, 2008 Author Share Posted June 26, 2008 Any one got any clues to this - it's all that's holding me back at the moment Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575021 Share on other sites More sharing options...
timmah1 Posted June 26, 2008 Share Posted June 26, 2008 Have you tried echoing the POST statement back to the field? site background: <input name="bg" type ="text" id="bg" value="<?php echo $_POST['bg']; ?>"/> Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575123 Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 <form id="colors" name="colors" method="post" action=""> <p>site background: <input name="bg" type="text" value="<?=$_POST['bg']?>" id="bg" /></p> <p>header border: <input name="hdrbdr" type="text" value="<?=$_POST['hdrbdr']?>" id="hdrbdr" /></p> <p>header background: <input name="hdrbg" type="text" value="<?=$_POST['hdrbg']?>" id="hdrbg" /></p> <p><input type="submit" name="Submit" value="Submit" /></p> </form> Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575128 Share on other sites More sharing options...
perthmetro Posted June 26, 2008 Author Share Posted June 26, 2008 didn't do a thing sorry - just found out another problem though... when I refresh the form all the fields become blank which then inturn makes all the text files go blank if I hit submit! I need the form to be repopulated by the existing values each time it loads otherwise I'll have to retype in all the values each time Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575135 Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 show all your code? Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575139 Share on other sites More sharing options...
timmah1 Posted June 26, 2008 Share Posted June 26, 2008 You need to open up the appropriate text file, and populate the fields with the data from the text files, before showing the form. Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575140 Share on other sites More sharing options...
timmah1 Posted June 26, 2008 Share Posted June 26, 2008 Then your form fields would be like this <input name="bg" type ="text" id="bg" value="<?php echo $bg; ?>"/> [/code Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575144 Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 Ok, my advice is create a page for just your form... my_form.php <form id="colors" name="colors" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <p>site background: <input name="bg" type="text" value="<?=$_POST['bg']?>" id="bg" /></p> <p>header border: <input name="hdrbdr" type="text" value="<?=$_POST['hdrbdr']?>" id="hdrbdr" /></p> <p>header background: <input name="hdrbg" type="text" value="<?=$_POST['hdrbg']?>" id="hdrbg" /></p> <p><input type="submit" name="Submit" value="Submit" /></p> </form> my_php.php <?php if(!$_POST['Submit']) include_once 'my_form.php'; else{ include_once 'my_form.php'; # your form print '<p>Text Here, below form.'; } ?> Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575154 Share on other sites More sharing options...
perthmetro Posted June 26, 2008 Author Share Posted June 26, 2008 can i email you the zip files it's too big to post here Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575158 Share on other sites More sharing options...
perthmetro Posted June 26, 2008 Author Share Posted June 26, 2008 here are all the files on display... http://snipplr.com/view/6931/dynamic-stylesheet/ Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575193 Share on other sites More sharing options...
perthmetro Posted June 26, 2008 Author Share Posted June 26, 2008 hi xyn, I'm not quite sure how the my.php fits in my situation? Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575194 Share on other sites More sharing options...
perthmetro Posted June 26, 2008 Author Share Posted June 26, 2008 All the files can be downloaded here... http://www.box.net/shared/70x4nlzaco Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575202 Share on other sites More sharing options...
perthmetro Posted June 27, 2008 Author Share Posted June 27, 2008 I've put a working example of this script here if anyone wants to try it.. The example is at http://www.perthmetro.net/cms4css/ the form to input your colours is at http://www.perthmetro.net/cms4css/values.php unfortunately the colours disappear as each time it is reloaded the text files get over written with a null/blank value. @xyn... i tried your way but i'm a bit/totally confused about how to go about to implement it.... the form is named html.txt for some reason? thanks for your help Pete Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575625 Share on other sites More sharing options...
Lodius2000 Posted June 27, 2008 Share Posted June 27, 2008 seems like you need an <input type="hidden" name="_submit_check" value="1" /> then change your if ($_POST){ to read if ($_POST['_submit_check']) { that should retain values that you have entered if there is a after submission, if there is some sort of an error you wont have to retype all the fields, it will remeber them. BUT the first time you load the page all the fields will be blank WARNING: untested code, but its basically what I do adapted to your style Link to comment https://forums.phpfreaks.com/topic/111896-how-do-i-stop-this-form-from-going-blank-after-i-press-submit/#findComment-575674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.