Jump to content

Beginners Code Help


VirgenAd

Recommended Posts

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
$content="


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

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

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 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
}
[/code]
I hope that helps some.
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.