Jump to content

Recommended Posts

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!

<?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>';

?>

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.

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.