Jump to content

Best way to validate 7+ fields w/o JS


bsamson

Recommended Posts

I have a form w/ 7 mandatory fields:
First Name, Last Name, City, Zip Code, Username, Password, and lastly Alias

What is the most efficient way to check for values of all those fields and redirect back if any are found to be empty ... The following is the way I have been doing this:

[code]<?php
if (empty($fname))  {
  header( ...
  } elseif {
  (empty($fname))  {
  header( ... 
//  ETC ... ETC ...
?>[/code]

Any suggestions?? ... Thanks!
Link to comment
https://forums.phpfreaks.com/topic/29357-best-way-to-validate-7-fields-wo-js/
Share on other sites

I would make a variable (string or array), so you can collect ALL missing fields in one go.  Just use a seperate "if" for each.

Then after the checks, check if there are any messages, and if so, redirect and pass along the message to be displayed.  You can do it with eg [code=php:0]header("Location: http://site.com/script.php?msg=" . urlencode($msg));[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.