jasonstairs Posted June 4, 2007 Share Posted June 4, 2007 Hello, I have an HTML Form with PHP code that verifies the input data and then enters the data into a MySQL table upon hitting the submit button, after which the page reloads due to the form action = "<?php echo $PHP_SELF;?>. Here is the form code: <!--Start the form...--> <form enctype="multipart/form-data" action="<?php echo $PHP_SELF;?>" method="post"> <fieldset><legend>Fill out the form to upload a file:</legend> <input type="hidden" name="MAX_FILE_SIZE" value="524288"> <p><b>Your Name: </b><input type="text" name="name" size="40" />(required)</p><br /> <?php // Create the inputs. for ($i = 0; $i < $counter; $i++) { echo '<p><b>File:</b> <input type="file" size="40" name="upload' . $i . '" />(required)</p> <p><b>Description:</b><br /> <textarea name="description' . $i . '" onKeyDown="limitText(this.form.description' . $i . ',this.form.countdown,500);" onKeyUp="limitText(this.form.description' . $i . ',this.form.countdown,500;" cols="40" rows="5">Enter a brief description of your CV here.</textarea><br /> <font size="3">(Maximum characters: 500)<br />You have <input readonly type="text" size="3" name="countdown" value="500"> characters left.</font></p><br />'; } ?> <p><b>Postdoc Termination Date (mm/yy): </b><input type="text" name="TermDate" size = "5" />(required)</p><br /> <p><b>Field: </b> <select name="field"> <option value ="NULL"></option> <option value ="Chemistry">Chemistry</option> <option value ="Physics">Physics</option> </select> <b>Discipline: </b> <select name="discipline"> <option value = ""</option> <optgroup label="Chemistry"> <option value ="Organic">Organic</option> <option value ="Physical">Physical</option> </optgroup> <optgroup label="Physics"> <option value ="Materials">Materials</option> <option value ="Nuclear">Nuclear</option> </optgroup> </select> (required)</p><br /> <?php echo '<p><font color="blue"><b>Enter up to 7 Keywords to describe your CV/technical field so employers can search for and find your CV.</b></font></p>'; for ($j = 0; $j < $keywords; $j++) { echo '<p><b>Keyword ' . ($j+1) . ': </b> <input type="text" name="key' . $j . '" size = "40" /></p><br />'; } ?> </fieldset> <input type="hidden" name="submitted" value="TRUE" /> <div align="center"><input type="submit" name="submit" value="Submit" /> <input type="reset" name="submit" value="Reset" /></div> </form> My question is, when the page reloads due to an error in the user input, how can I have the user's data reappear on the ($PHP_SELF) page reload so that they don't have to fill in their data all over again? Can someone please point me in the right direction...example code would be great! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/54164-solved-if-error-carry-html-form-data-to-php_self/ Share on other sites More sharing options...
Caesar Posted June 4, 2007 Share Posted June 4, 2007 <?php echo' <form method="post" action="'.$_SERVER['PHP_SELF'].'"> <table> <tr><td><input type="text" name="field1" value="'.$_POST['field1'].'"></td></tr> <tr><td><input type="submit" name="submit" value="Do It!"></td></tr> </table> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54164-solved-if-error-carry-html-form-data-to-php_self/#findComment-267778 Share on other sites More sharing options...
bonaparte Posted June 4, 2007 Share Posted June 4, 2007 Hi, You need to use the value attribute in the HTML forms. For example: <input type="text" name="name" size="40" value="<?php echo $_POST['name'];?>" /> value="<?php echo $_POST['name'];?>" is what you are looking for. Similarly you need to display the value for all the form fields. Quote Link to comment https://forums.phpfreaks.com/topic/54164-solved-if-error-carry-html-form-data-to-php_self/#findComment-267787 Share on other sites More sharing options...
jasonstairs Posted June 4, 2007 Author Share Posted June 4, 2007 I tried that but it doesn't seem to be working for me right now. Also, is it the same for a "textarea" and also what about the "select/optgroups"? Also, can you set the value for the type="file"? I will keep working on it but anymore information would be appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/54164-solved-if-error-carry-html-form-data-to-php_self/#findComment-267886 Share on other sites More sharing options...
jasonstairs Posted June 4, 2007 Author Share Posted June 4, 2007 OK, I was just confused by my own code...trying to do too many things at once, but I got it to work on all fronts. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/54164-solved-if-error-carry-html-form-data-to-php_self/#findComment-267915 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.