Jump to content

email form question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
bukymast3r

bukymast3r

    Newbie

  • Members
  • Pip
  • 9 posts
Hi ppl, :)


I've stack in a part where I need to define the requirements to send email.

I have fields in my form like this:


<span class="parts"><input type="text" name="amount1" value="0" class="amount_parts" /></span>

<span class="parts"><input type="text" name="amount2" value="0" class="amount_parts" /></span>

<span class="parts"><input type="text" name="amount3" value="0" class="amount_parts" /></span>

<span class="parts"><input type="text" name="amount4" value="0" class="amount_parts" /></span>

<span class="parts"><input type="text" name="amount5" value="0" class="amount_parts" /></span>

<span class="parts"><input type="text" name="amount6" value="0" class="amount_parts" /></span>



I would define, when this input field have a value of 0, that this value is not sent with the mail function.

A part of my mail.php:
$message ="Part1 - " . $_POST["amount1"] . " parts/a\r\nPart2 - ". $_POST["amount2"] . " parts/a\r\nPart3 - " . $_POST["amount3"] . " parts/a\r\nPart4 - " . $_POST["amount4] . " parts/a\r\nPart5 - " . $_POST["amount5"] . "parts/a\r\n\nPart6:\r\n" . $_POST["amount6"]; 

.....


So, if a user fill the 3th, 4th 5th field with some number that are not 0, and leaves the 1st, 2nd and 6th field with the default value (value of 0), I would like that the mail function send only fields with numbers that are not 0.

Thx in advance! :)

#2
Guest_johnny.dacu_*

Guest_johnny.dacu_*
  • Guests
What is so hard to check values and if they are grate than 0 then pass the value into an array. Finally you send only data from array

#3
bukymast3r

bukymast3r

    Newbie

  • Members
  • Pip
  • 9 posts
Ty johnny for your answer, but, Im not so familiar with PHP, can you show just in short how to do that? :) ty in advance!

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
This should work:
$out = "";
for($i=1;$i<=6;$i++) {
     if(!isset($_POST["amount$i"])) {
         $_POST["amount$i"] = 0; //default value
     } else {
         $out .= "Part$i - {$_POST['amount$i']}\r\n"; //Slug here
     }
}

//out will only contain forms that were filled out

Edited by Alexander, 02 August 2010 - 02:55 AM.
Need coffee, fixed example to better suit problem.

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
bukymast3r

bukymast3r

    Newbie

  • Members
  • Pip
  • 9 posts
I will try it, ty Nullw0rm :)

#6
bukymast3r

bukymast3r

    Newbie

  • Members
  • Pip
  • 9 posts
Tried that, but I get only:


Part1 -

Part2 - 

Part3 - 

Part4 - 

Part5 - 

Part6 - 


Don't get the amounts :S

#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
change
$out .= "Part$i - {$_POST['amount$i']}\r\n"; //Slug here
to
$out .= "Part$i - ".$_POST["amount$i"]."\r\n"; //Slug here
{}-evaluation can be good at time, but at many times it's just not the best option,
as in this case, the string inside the post brackets also needed an evaluation
I think the code is more easily read this way too.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#8
bukymast3r

bukymast3r

    Newbie

  • Members
  • Pip
  • 9 posts
Worked now, ty Orjan,

but, I get also fields that have default value of 0

Part1 - 2

Part2 - 0

Part3 - 3

Part4 - 0

Part5 - 1

Part6 - 0



#9
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Then it's even easier code, just do this....
$out = "";
for($i=1;$i<=6;$i++) {
    $out .= "Part$i - ".$_POST["amount$i"]."\r\n";
}

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall