IF Help

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
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

IF Help

Post by bla5e »

Code: Select all

if (!$name) {echo "You must enter your full name. Please "; } else {
if (!$age) {echo "We need your Age. "; } else {
if (!$email) {echo "We must know your e-mail address to get back to you."; } else {
if (!$city) {echo "Please fill out the location section. "; } else {
if (!$state) {echo "Please fill out the state section. "; } else {
if (!$qualify) {echo "You didn't tell us why you are qualified. ";} else {
if (!$other) {echo "Please tell us why we should pick you over someone else. "; } else {
if (!$sales) {echo "Please tell us how you would approach sales. "; } else {
how do i make it so it collects all the unfilled/empty variables into 1 echo?

Example: Name, Email and State isnt filled out, echos back "Please fill out your: name, email and state"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Push each empty one into an array. A bit of logic will then be applied on the number of elements in the array. Where the number of elements is greater than one, the last element is popped off followed by the rest being imploded and finally the popped element is concatenated onto the string with "and" added.
Post Reply