VirgenAd Posted June 5, 2006 Share Posted June 5, 2006 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 eregiif (!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 $content=" A visitor at $sitename has left the following information:\nE-Mail: $emailName: $nameStreet: $streetCity: $cityZip: $zipCountry: $countryPhone: $phoneRealtor: $realtor[/quote]Thanks ahead of time for your help. Quote Link to comment https://forums.phpfreaks.com/topic/11248-beginners-code-help/ Share on other sites More sharing options...
.josh Posted June 5, 2006 Share Posted June 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11248-beginners-code-help/#findComment-42102 Share on other sites More sharing options...
localhost Posted June 5, 2006 Share Posted June 5, 2006 if($var1==NULL || $var2==NULL || $var3==NULL) {echo " All fields are REQUIRED.";}if thats what you mean Quote Link to comment https://forums.phpfreaks.com/topic/11248-beginners-code-help/#findComment-42112 Share on other sites More sharing options...
VirgenAd Posted June 5, 2006 Author Share Posted June 5, 2006 Crayon, 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.localhost, 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. Quote Link to comment https://forums.phpfreaks.com/topic/11248-beginners-code-help/#findComment-42122 Share on other sites More sharing options...
Buyocat Posted June 5, 2006 Share Posted June 5, 2006 What I think crayon is suggesting is the following: you collect each value into an array like so:[code]$array = array(); // create array$array[] = $email; // add new value$array[] = $firstname; // add another new value// etc[/code]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:[code]if (strlen($firstname) > 0 and $firstname != '') // verify it's a real string$array[] = $firstname; // add it[/code]Finally once you've done this you can do this:[code]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}[/code]If you want to tell the user what sort of data wasn't entered then I suggest using an associative array such as:[code]$email = somewhere@someplace.com$array['email'] = $email; // this sort of makes something like email = $email in the array ...// then later you canforeach ($array as $key => $value) { // this will loop through each entry and give you the key-value parisecho $key . ' = ' . $value; // this will output email = somewhere@someplace.com}[/code]I hope that helps some. Quote Link to comment https://forums.phpfreaks.com/topic/11248-beginners-code-help/#findComment-42160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.