0

i have a small problem, i'm using a PHP form to get answers off a contact form I created.

Here is the php:

$email_message .= "E-Commerce: \n";
$email_message .= (isset($_POST['no-credit'])) ? 
                      "No credit card: $".implode(" ", $_POST['no-credit'])."\n" : '';
$email_message .= (isset($_POST['paypal'])) ? 
                      "Paypal: $".implode(" ", $_POST['paypal'])."\n" : ''; 

When i get the email, and "paypal" or "no credit" is not checked "E-commerce:" still shows up. I tried something like:

$email_message .= (isset($_POST['no-credit'])) ? (isset($_POST['paypal'])) ?
                      "E-Commerce: \n";
$email_message .= (isset($_POST['no-credit'])) ? 
                      "No credit card: $".implode(" ", $_POST['no-credit'])."\n" : '';
$email_message .= (isset($_POST['paypal'])) ? 
                      "Paypal: $".implode(" ", $_POST['paypal'])."\n" : ''; 

But it did not work, i fell like i'm not far away but i can not get my hands on it.

Thanks

0

2 Answers 2

1

Change your condition to !empty() also you missing the : part in your ternary condition for else part,

$email_message .= (!empty($_POST['no-credit']) ) ? 
                      "No credit card: $".implode(" ", $_POST['no-credit'])."\n" : "";
Sign up to request clarification or add additional context in comments.

5 Comments

@ShankarDamodaran - Agree. Habitual problem :)
Removed my comment :) +1
@ShankarDamodaran what about the E-commerce line? i dont get it sorry
@Rikesh i tried that but No credit card appears in the email even though it's not checked
var_dump($_POST['no-credit']) & check if you getting anything in it.
0

change your second example like this. But when i tried with my localhost it is working with this code.

$email_message .= (!empty($_POST['no-credit'])) ? ((!empty($_POST['paypal'])) ?"E-Commerce: \n":""):""; 
$email_message .= (empty($_POST['no-credit'])) ? 
                      "No credit card: $".implode(" ", $_POST['no-credit'])."\n" : '';
$email_message .= (empty($_POST['paypal'])) ? 
                      "Paypal: $".implode(" ", $_POST['paypal'])."\n" : ''; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.