PDA

View Full Version : php sticky form fields wont update



JMCDesigner
19 Oct 2010, 06:44 AM
I have a form which loads its values from a text file. When I update a field and press submit, the text file is updated with the new value but the sticky field still shows the prior value. Can anyone enlighten me as to what I've done wrong? It's far too late in the evening and my brain has become mush...

form fields look like this:


<input type="text" name="businessname" id="businessname" <?php stickyfield($SET_BNAME); ?>/>

external config file (php include) looks like this:


function stickyfield($fieldname){
if(isset($fieldname)){echo ' value="'.trim($fieldname).'"'; };
};

I have ommited the other data but $SET_BNAME refers to the array element im extracting from the text file as follows:


$settingsfile = file(SETTINGS);

for ($i = 0; $i < count($settingsfile); $i++) {
// separate each element and store in a temporary array
$tmp = explode(': ', $settingsfile[$i]);
// assign each element of the temporary array to a named array key
$settingsfile[$i] = array('setting' => $tmp[0], 'value' => $tmp[1]);
}
$SET_BNAME = trim($settingsfile[0]['value']);

(SETTINGS is defined to text file location)



HOW IT WORKS/DOESNT WORK:


1. My form input field reads specific line from text file and makes field value (as an example) 'plumbing inc'
2. I change the input field to 'electrician inc' and press submit
3. The specific line on the text file is updated to 'electrician inc', but the form field still says 'plumbing inc'

JMCDesigner
19 Oct 2010, 09:21 AM
Fair enough....solved it myself...I put a header location redirect and changed text field code


<input type="text" name="businessname" id="businessname" <?php if (!in_array('businessname', $missing)){stickyfield($SET_BNAME);} ?>/>