Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Values

Status
Not open for further replies.

patrickstrijdonck

Programmer
Jan 18, 2009
97
NL
Hi all,

When i try to submit a form, and it returns that i forgot a field,

its will now return with
Code:
 header
function,
but then the fields are empty, what im trying to do is, if a field is empty, it will die()

i replaced the die() with header, so the page will open again and is not empty, but then the fields who were filled in, must now also be filled in....


any ideas?
 
the basic premise is like this (of course classes etc make this kind of thing a bit neater)

Code:
if (isset($_POST['submit'])){
   if (formValid()){
    processForm();
  } else {
    displayForm(true);
  }
} else {
  displayForm(false);
}

function formValid(){
 //check form submission validity
}

function processForm(){
 //process the incoming variables
}
function displayForm($sticky=false){
 $fields = array ('field1', 'field2');
 foreach ($fields as $field){
  if($sticky){
   $$field = '';
  else { 
   $$field = empty($_POST[$field]) ? '' : $_POST[$field];
   } 
 }
 echo <<<HTML
<form>
 <input type="text" name="field1" value="$field1" /><br/>
 <input type="text" name="field2' value="$field2" /><br/>
 <input  name="submit" value="submit" type="submit" />
</form>
HTML;
}
 
You could use session variables and just set value="<?=_SESSION['blah']?>"

Olav Alexander Mjelde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top