/    Sign up×
Community /Pin to ProfileBookmark

email only values > 0

I have a form and I’m trying to email some of the form fields, but I only want to include them in the email body if their value is greater than 0

For example, if there’s no phone extension, I dont want it included as an empty value in the email. Exactly where & how do I perform the test of the values before they get included into the email body ?

My mail is structured like

[code=php]
$message = ” $todayis [PST] n
Customer $first_namen
$phone_number . EXT $phone_extensionn
$messageme = ” $message n
$from = “From:$fromEmailrn”;
mail($myemail, $subject, $messageme, $from);
[/code]

Thanks

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@nickosmonOct 16.2011 — If there is no value in the extension table for a particular record, I don't believe it should output anything. The only problem that I see is outputting EXT when there is not extension.

This is what I would do :

Change line 3 to this:

$phone_number . $phone_extensionn

And then create a simple if statement above that code:

if ($PHONE_EXT_VAR > '0') {

$phone_extension = "EXT ".$PHONE_EXT_VAR;

}

else {

$phone extension = " ";

}

That way if there is an extension, the variable $phone_extension will carry the text "EXT" too, so it won't display unless there is an extension.

Also, insert whatever variable into $PHONE_EXT_VAR that carries the extension value from your database.

Please tell me if you need me to explain something further to you.
Copy linkTweet thisAlerts:
@eval_BadCode_Oct 16.2011 — . Exactly where & how do I perform the test of the values before they get included into the email body ?[/QUOTE]

You can compare them anywhere you want (just about).

This might work:

[code=php]
ob_start();
echo ( $todayis ? "$todayis [PST]" : '' ) . "n";
echo ( $first_name ? "Customer $first_name n" : '' );
echo ( $phone_number ? " EXT $phone_extensionn " : '' );
$message = ob_get_contents(); ob_clear();
[/code]
Copy linkTweet thisAlerts:
@simoraauthorOct 17.2011 — Eval Thanks!

However, I did not understand your responce.

Maybe I did not make my intent clear.

At the top of my code, if I have for example

[code=php]
$phone_number=$_POST["phone_number"];
$phone_extension=$_POST["phone_extension"];
[/code]


I want to do something like;

[code=php]
if ($POST["phone_extension"] <> "") { $messageme .= "The phone extension is " . $POST["phone_extension"]; }
[/code]


Still working on the DETAILS of it, but this is along the lines of what I was looking for.

Thanks
Copy linkTweet thisAlerts:
@simoraauthorOct 17.2011 — nickosmon :

Seems like it should have worked, but it didn't .

I kept getting an error, but if I removed the else part ( crude ) I can force it to work.

I'm trying to get a similar construction to work with radio buttons. Same problem. I can get the selected value to pass to another page, but I can't get the value pairs to be emailed.

Any ideas .

Thanks
Copy linkTweet thisAlerts:
@eval_BadCode_Oct 17.2011 — $POST != $_POST

you need the underscore _

I guess I can explain this....

This is the bare minimum:

[code=php]<?php

if(isset($_POST['submit'])) {
list($to, $subject, $message, $headers) = array("[email protected]", 'how to form','','From: [email protected] ' ."rn");
$message = isset($_POST['isPhone']) && isset($_POST['phone'] && $_POST['isPhone'] ? 'Phone number: ' . $_POST['phone'] : '';
if(mail($to, $subject, $message, $headers)) die('yeah it worked');
}

?>
<form target="_self" method="post">
Are you using a phone: [Yes <input type="radio" value="1" name="isPhone" /> ] [No <input type="radio" name="isPhone" value="0" />
<br />
If so, enter your phone number: <input name="phone" type="text" />
<br />
<input type="submit" value="click here when you're done" name="submit" />
</form>[/code]
Copy linkTweet thisAlerts:
@simoraauthorOct 17.2011 — eval:

I think that you're answering a different question. ( how to send email unless a value is 0. ) rather than how to exclude a specific value pair like nickosmon shows.

nickosmon : provided a workable logical solution. What I'm trying to ascertain is why the else portion of it is causing an error.

This is the logic portion that I'm troubleshooting.

[code=php]
if ($PHONE_EXT_VAR > '0') {
$phone_extension = "EXT ".$PHONE_EXT_VAR;
}
else {
$phone extension = " ";
}[/code]

Thanks for the efforts.
×

Success!

Help @simora spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...