php form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

php form

Post by eektech909 »

i have a php form that adds info to a sql table to dynamically load on a website.
when they click submit it runs a PHP_SELF to reload the page and validates the form for blank boxes,etc...
how can i set it up so when it finds the error it keeps the current information in the text boxes rather than clearing them out
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

store the values of each form into a variable and then print the variable into value on the page:
Validation script

Code: Select all

<?php
$title = some_type_of_filter($_POST['title']);
?>
<input type="text" name="title" value="<?php echo $title; ?>" />
Does that make sense?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Well, if your page is reloading when there's an error, and you're not SUBMITTING any data for PROCESSING yet.. but just offering the form to the user again, something along the lines of this would be perfect:

Code: Select all

<input type="text" name="myTextField" size="20"<?php
if(!empty($_POST['myTextField'])){
   echo ' value="'.htmlentities($_POST['myTextField'],ENT_QUOTES).'"';
}
?>>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

Post by eektech909 »

how do i get the value of the text boxes to go blank after the correct info has been submitted?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You remove the form from the equation. On first load, show the form. On submit, check the passed data. If it validates, process the data and show a success message, not the form. If the data does not validate, show an error message AND the form.
Post Reply