Reputation: 3671
I'm looking to nest two conditionals within another conditional (if that makes sense) of an if statement. Let me explain.
I have a form. I have name, email and then I have two textareas (one represented by $designer_program and one by $_designer_language). One textarea is for designers who are filling out the form and one textarea is for programmers who are filling out the form. They only need to fill out one BUT one must be filled out. So the if statement I'm using in my PHP is as follows:
if (isset($_POST['designer_name']) && isset($_POST['designer_email']) && isset($_POST['designer_program'])){
etc.
That's good but I want to do either designer_program OR designer_language. Basically I tried something like this:
if (isset($_POST['designer_name']) && isset($_POST['designer_email']) && isset(($_POST['designer_program']) || ($_POST['designer_language'])){
but I guess you can't nest conditionals like that? I'm sure there's an easy syntactic solution but I can't find it. Thanks.
Here's the full code:
<?php
if (isset($_POST['designer_name']) && isset($_POST['designer_email']) && isset($_POST['designer_program'])){
$designer_name = $_POST['designer_name'];
$designer_email = $_POST['designer_email'];
$designer_program = $_POST['designer_program'];
$designer_language = $_POST['designer_language'];
if(!empty($designer_name) && !empty($designer_email) && !empty($designer_program)){
$to = '[email protected]';
$subject = 'Test Application: '.$designer_name;
$body = "Test Application";
$headers = 'From: '.$designer_email;
if (@mail($to, $subject, $body, $headers)){
echo '<script type="text/javascript">document.location.href="thankyou.php";</script>';
}
}
else{
echo '<script type="text/javascript">
window.alert("Please fill out all fields.");
</script>';
}
}
?>
Upvotes: 0
Views: 195
Reputation: 91742
Your logic fails because all text-areas are sent in, regardless whether they contain information or not.
You need to make one check for a POST
and then check using the conditionals you have for non-empty values instead of set values.
if (isset($_POST['designer_name'])
{
if (!empty() && !empty() && ( !empty() || !empty() ))
{
Upvotes: 1