LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-21-2009, 04:31 PM   #1
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Rep: Reputation: 16
processing forms with PHP


I am trying to process an email form using PHP.It is working okay so far but I want the Items to be displayed as a list when the email is received.
eg.

one
two
three
four

and not

one two three four

here is a copy of the variable that displays the message
 
Old 01-21-2009, 04:57 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 15,098

Rep: Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719Reputation: 2719
Quote:
Originally Posted by 3vra View Post
I am trying to process an email form using PHP.It is working okay so far but I want the Items to be displayed as a list when the email is received.
eg.

one
two
three
four

and not

one two three four

here is a copy of the variable that displays the message
Don't have the variable...you didn't attach it. Check out the PHP manual at http://us.php.net/explode, specifically, the explode command.
 
Old 01-22-2009, 09:23 AM   #3
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Original Poster
Rep: Reputation: 16
Variable I left out (item)

foreach ($_POST['MLIS'] as $item){
$items .= $item." ";

}

here is the copy of the variable I left out
 
Old 01-22-2009, 11:30 AM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by 3vra View Post
foreach ($_POST['MLIS'] as $item){
$items .= $item." ";

}

here is the copy of the variable I left out
$items .= $item."\n";
 
Old 01-23-2009, 03:20 PM   #5
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Original Poster
Rep: Reputation: 16
could someone please explain to me why this codes sends only the information checked in the check boxes and not the text boxes.


<tr>
<td><input type="checkbox" name="MLIS[]" value="Notepads" />Notepads</td>
<td><input type="text" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }" ></td>
</tr>

this is the code used for sending the items to the email but only the items in the check boxes show up

foreach ($_POST['MLIS'] as $item){
$items .= $item ."\n";


the items are stored in the php variable $items
 
Old 01-23-2009, 04:15 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 12,162

Rep: Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784
You really have not provided enough of your code. However, from what you did post the text box is not stored in the MLIS array.
 
Old 01-23-2009, 05:32 PM   #7
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by michaelk View Post
You really have not provided enough of your code. However, from what you did post the text box is not stored in the MLIS array.

<form name"MUD LAB INVENTORY SYSTEM" method="post" action="index.php">
<tr>
<td><input type="checkbox" name="MLIS[]" value="Notepads" />Notepads</td>
<td><input type="text" name="quantity_1" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }" ></td>
</tr>
<tr>
<td><input type="checkbox" name="MLIS[]" value="Envelopes" />Envelopes</td>
<td> <input type="text" name="quantity_2" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td>
</tr>
<tr>
<td><input type="checkbox" name="MLIS[]" value="Staples" />Staples</td>
<td><input type="text" name="quantity_3" size="1" maxlength="2"onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td>
</tr>
<tr>
<td><input type="checkbox" name="MLIS[]" value="Post It Notes" />Post It Notes</td>
<td><input type="text" name="quantity_4" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td>
</tr>
<tr>
<td><input type="checkbox" name="MLIS[]" value="Red Ink Pens" />Red Ink Pens</td>
<td><input type="text" name="quantity_5" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"> </td>
</tr>
<tr>
<td><input type="checkbox" name="MLIS[]" value="Black Ink Pens" />Black Ink Pens</td>
<td> <input type="text" name="quantity_6"size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"> </td>
</tr>
<tr>
<td><input type="checkbox" name="MLIS[]" value="Red Ink Pens" />Blue Ink Pens</td>
<td><input type="text" name="quantity_7" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td>
</tr>
<tr>
<td><input type="submit" value= "Send"></td>
</tr>
</form>
</table>
<?php
}
else{
error_reporting(0);
$email="somebody@somewhere.com"
$subject="Subject";
$body= "Dear Joyce,\n\nBelow is a list of all the items that are currently needed at the Mud Lab:";
$items="";
$footer = "Regards"." "."staff_member";
$staff_member = "Staff Member";
foreach ($_POST['MLIS'] as $item){
$items .= $item ."\n";
}
$msg_body = $body."\n\n$items.\n\n".$footer;
$recipient = "somebody@somewhere.com";
$from = stripslashes($email);
$subject = stripslashes("Test Mail");
$msg = "Message from: $from\n\n".stripslashes($msg_body);
$header = 'From: "somebody@somewhere.com"'."\r\n".'Reply-To: $staff_member'."\r\n". 'X-Mailer: PHP/' . phpversion();
if (mail($recipient, $subject, $msg, $header)){
echo ("<b>Message Sent To:</b> $recipient");
} else
echo "Message failed";
}

Last edited by 3vra; 01-23-2009 at 05:40 PM.
 
Old 01-23-2009, 09:44 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 12,162

Rep: Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784
Homework?
 
Old 01-26-2009, 09:56 AM   #9
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by michaelk View Post
Homework?
No.I'm just learning HTML and PHP and trying things out.I just need an explanation on what's going on so I can understand why I am not getting the results I want.
 
Old 01-26-2009, 11:33 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 12,162

Rep: Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784
Your PHP code is only processing the MLIS array which only contains check box values. You need to get the data from the text boxes. It is possible to use an array for the text boxes but the lengths will be different i.e. MLIS vs textbox.
 
Old 01-26-2009, 12:08 PM   #11
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by michaelk View Post
Your PHP code is only processing the MLIS array which only contains check box values. You need to get the data from the text boxes. It is possible to use an array for the text boxes but the lengths will be different i.e. MLIS vs textbox.
\

now I get it.I used an array for the text boxes used another foreach statement with the required variables for the text boxes and it worked.Thanks man
 
Old 02-12-2009, 01:52 PM   #12
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Original Poster
Rep: Reputation: 16
the logic seems right but it does not work

I am trying to write a block of code in php that will echo an error if the value entered in a text box is not an integer.The logic behind the code seems correct but when the form is processed it returns the erro message even if the value entered is an int.

SAMPLE CODE
===========
if (($_POST['quantityBox'.$i] != "") && (! is_int ($_POST['quantityBox'.$i]))) {
$errorMessage[] = "only numbers are allowed in the quantity box!";
}
 
Old 02-12-2009, 02:41 PM   #13
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,111

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
first of all it might be better to replace
Code:
($_POST['quantityBox'.$i] != "")
with
Code:
(isset(($_POST['quantityBox'.$i]))
second, form input always returns as a string, try

is_numeric() instead of is_int()
 
Old 02-12-2009, 02:50 PM   #14
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by frieza View Post
first of all it might be better to replace
Code:
($_POST['quantityBox'.$i] != "")
with
Code:
(isset(($_POST['quantityBox'.$i]))
second, form input always returns as a string, try

is_numeric() instead of is_int()

is_numberic () was the correct funtion to use. THANKS!
 
Old 02-12-2009, 03:24 PM   #15
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,111

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
yw
p.s. the first one i mentioned the ($_POST['quantityBox'.$i] != "") vs (isset(($_POST['quantityBox'.$i])) at first blush may not seem to be any different but especially when dealing with checkboxes the variable is only null until its been used once then it becomes an array of nulls if nothing is selected, isset() should be able to deal with that but if !="" will not.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
master - details forms with php htamayo Programming 1 04-09-2008 05:48 PM
PHP having issues while accepting variables from forms ashesh0326 Programming 4 05-07-2007 08:01 AM
LXer: Html Forms and PHP LXer Syndicated Linux News 0 01-09-2007 02:33 AM
PHP & Apache - php files not processing aolong Linux - General 1 12-17-2006 04:09 AM
passing an array from html-forms to php prabhatsoni Linux - Software 2 06-04-2005 01:11 AM


All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration