newbtophp Posted August 10, 2009 Share Posted August 10, 2009 Im using $_POST to submit to variables in my config file, but the problem is everytime I view the form, the fields are blank so it looks like the variables are empty. Is their a way I can make the field default values be whatever is currently in the variables?. So for example if I edit the form and I add phpfreaks.com to the siteurl field, everytime I visit that form the default value of that field would be that? (unless changed). My code: <?php include("config.inc.php"); echo "<form action='form.php' method='post' name='Form'>"; ?>Website Url: (this edits $siteurl)<BR> <input type="text" name="siteurl" size="25"><BR><BR> Website Title: (this edits $site_title)<BR> <input type="text" name="site_title" size="25"><BR><BR> Your Email: (this edits $email)<BR> <input type="text" name="email" size="25"><BR><BR> <input name="submit" type="submit" value="Submit"> </form> <?php if(!empty($_POST["submit"])) { $out='<?php //Website Url $siteurl="'. (isset($_POST["siteurl"])? $_POST["siteurl"]:'') .'"; //Website Title $site_title="'. (isset($_POST["site_title"])? $_POST["site_title"]:'') .'"; //Your Email $email="'. (isset($_POST["email"])? $_POST["email"]:'') .'"; ?>'; file_put_contents("config.inc.php",$out); } ?> Thanks for your help Quote Link to comment Share on other sites More sharing options...
perrij3 Posted August 10, 2009 Share Posted August 10, 2009 I think you can add a value tag to the input tag and it will place a default value in your input box. Something like this: <input type="text" name="siteurl" size="25" value="http://www.phpfreak.com"> Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 10, 2009 Author Share Posted August 10, 2009 That would not auto update when editing the field. Im trying to get the variable content to display within each field by default. The form edits the variable. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 10, 2009 Share Posted August 10, 2009 It seems you want the form to retrieve data from config.inc.php and display it on the forms to edit? <input type="text" name="site_title" size="25" value="<?=$title;?>"> $title will be whatever was the variable in config.inc.php.. So it'd show.. Form: [My site!], instead of blank. Quote Link to comment Share on other sites More sharing options...
perrij3 Posted August 10, 2009 Share Posted August 10, 2009 Sorry, didn't read everything fully. Getting a little tired here. Anyways, I would have to agree with oni-kun on how it should be done. Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 10, 2009 Author Share Posted August 10, 2009 Thanks both of you for you help. I can't believe I didnt think of that Quote Link to comment 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.