Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1065307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:47:06+00:00 2026-05-16T19:47:06+00:00

I’m sorry if this is a very simplistic question but I’m still learning the

  • 0

I’m sorry if this is a very simplistic question but I’m still learning the ropes of PHP.

I’m writing a mail script in PHP that takes the contents of a form and sends it out to one of two emails. I had it working perfectly but the person for whom I’m creating it came back with some edits and now I’m struggling.

Essentially, there are two sets of radio button where if “Yes” is checked another “additional information” field also needs to be filled in. If “No” is check, the other field can remain blank.

This is what I have so far:

if ($var1 == "String" AND $var2 =="")
{
    echo("Fill in the blah field");
}
elseif ($var3 == "Yes" AND $var4 == "") 
{
    echo ("Fill in the blah blah field");
}
elseif ($var1 !="" AND $var2 !="" AND $var7 !="")
{
    mail(....)
    echo(....)
}

I know there has to be a better way to first check if one set validates, then if the other does, and then if all the required fields are filled in…. Currently when I submit the form all I get is a blank screen.

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T19:47:07+00:00Added an answer on May 16, 2026 at 7:47 pm

    Your description and the code don’t seem related to me, but I’m confused by the variables named ‘var’ and the ‘blah’ fields. But, based on your description, maybe this will help you.

    $set_2_required = !empty($_GET['radio_set_1'] && $_GET['radio_set_1'] == 'yes';
    
    if ($set_2_required && empty($_GET['radio_set_2'])){
        echo 'ERROR: You must fill out radio set 2.';
    } else {
        // Send your mail.
    }
    

    EDIT: I think my previous comment has all the logic pieces of what you need, but maybe this will be closer to what you’d actually write.

    // With these ternary operators, you logic further down can rely on a NULL
    // value for anything that's not set or an empty string.
    $dropdown_1 = !empty($_GET['dropdown_1']) ? $_GET['dropdown_1'] : NULL;
    $dropdown_2 = !empty($_GET['dropdown_2']) ? $_GET['dropdown_2'] : NULL;
    $field_1 = !empty($_GET['field_1']) ? $_GET['field_1'] : NULL;
    $field_2 = !empty($_GET['field_2']) ? $_GET['field_2'] : NULL;
    
    // This 'valid' variable lets you avoid nesting and also return multiple errors
    // in the request.
    $valid = TRUE;
    if (!$field_1 && $dropdown_1 == '<string makes field required>'){
        echo 'ERROR: Field 1 is required for this dropdown selection.';
        $valid = FALSE;
    }
    if (!$field_2 && $dropdown_2 == '<string makes field required>'){
        echo 'ERROR: Field 2 is required for this dropdown selection.';
        $valid = FALSE;
    }
    
    // A final check if the logic gets complicated or the form on the front end
    // wants to check one thing to determine pass/fail.
    if (!$valid){
        echo 'ERROR: One or the other fields is required.';
    } else {
        // Everything's fine, send the mail.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I used javascript for loading a picture on my website depending on which small
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.