Jump to content


Beginners Code Help

  • Please log in to reply
4 replies to this topic

#1 VirgenAd

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 June 2006 - 04:42 PM

I need some help on figuring out how to add more "required fields" in this code. I want to make all of my text box fields required for this e-mail form. Here's my current code:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
// I checked the required fields in PHP because it has some nice features like eregi
if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $email)) {
$response = 'Email error';
}else if (($length = strlen($name))<1 ){
$response = 'Name required';
} else { // OK let's send off some e-mails
$response = "THANx"; // thus the flash movie advances to the thank you screen

A visitor at $sitename has left the following information:\n

E-Mail: $email
Name: $name
Street: $street
City: $city
Zip: $zip
Country: $country
Phone: $phone
Realtor: $realtor[/quote]

Thanks ahead of time for your help.

#2 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 June 2006 - 06:25 PM

if you make your textbox fields an array like texbox[] as the name then you can do a foreach loop around the condition you have for that textbox.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 localhost

  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 05 June 2006 - 06:42 PM

if($var1==NULL || $var2==NULL || $var3==NULL) {
echo " All fields are REQUIRED.";

if thats what you mean

#4 VirgenAd

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 June 2006 - 06:54 PM

To be honest with you, a co-worker help me put this together. This is for an e-mail form in flash. The flash part I can do, this php stuff, I have no clue. So I don't know how to set up what you're suggesting.

Would I type that in place of the copy I have now? And where would the "All fields are REQUIRED" show up?

Thanks again for all of your help, you two.

#5 Buyocat

  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 05 June 2006 - 07:45 PM

What I think crayon is suggesting is the following: you collect each value into an array like so:
$array = array(); // create array
$array[] = $email; // add new value
$array[] = $firstname; // add another new value
// etc
It would probably be a good idea to screen the data like you were doing with eregi and strlen to make sure that things are just empty strings or totally bizarre data. So you might have it like this:
if (strlen($firstname) > 0 and $firstname != '') // verify it's a real string
$array[] = $firstname; // add it
Finally once you've done this you can do this:
if (count($array) < 6) { // count counts the number of entries in the array, I just picked 6 whatever number you want is ok
// do stuff
} else {
// alert the user that information wasn't entered
If you want to tell the user what sort of data wasn't entered then I suggest using an associative array such as:
$email = somewhere@someplace.com
$array['email'] = $email; // this sort of makes something like email = $email in the array ...
// then later you can
foreach ($array as $key => $value) { // this will loop through each entry and give you the key-value paris
echo $key . ' = ' . $value; // this will output email = somewhere@someplace.com
I hope that helps some.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users