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
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]
Link to comment
Share on other sites

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.