Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php email, getting html field variables
Old 10-27-2008, 07:58 PM php email, getting html field variables
Average Talker

Posts: 25
Trades: 0
I am trying to get a test email page working. Here is a section from a form that I have:

Code:
   <p> Comments or Questions: <br>
   <input type="text" name="$comments" size="100" maxlength="250" >
   </p>

I think the name of the field is comments. (I may well be wrong.) Is this the correct way to print out the text in that variable:

<?php
print( "variable comments contains < $comments >\n" );
?>

Part of the problem is I don't have a trigger to decide when to execute the php email statement. The HTML for the submit button looks like this:

Code:
 
  <input type="submit" name="submit" value="Submit Now" >
I am expecting to write something like this, but I don't know how to get the variable:

Code:
<?php
if( $submit = true )
{
$email_status = mail( $to, $subject, $message );
}
?>
What do I need to change here?
If you want to see the page it is here:
http://www.bkelly.ws/test/phpmail.php
But obviously, it is subject to change
bkelly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-27-2008, 08:13 PM Re: php email, getting html field variables
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
$comments is php syntax not html. By setting the name of your field to $comments you've literally called it $comments.

http://www.w3schools.com/php/php_forms.asp
http://www.w3schools.com/php/php_post.asp
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-27-2008, 08:53 PM Re: php email, getting html field variables
Average Talker

Posts: 25
Trades: 0
I remain a bit confused. Here is my form and two php statements to deal with the variables:

Code:
 
<form method= "post" enctype="multi-part/form-data" action="http://www.fatcow.com/scripts/formemail.bml"> 
      <input type="hidden" name="my_email" value="webmail@bkelly.ws"> 
<!-- create form for user input -->
   <p> Subject: <br>
   <input type="text" name="subject" size="25" maxlength=50 >
   <input type="hidden" name="subject" value="email test">
   </p>
   <p> Comments or Questions: <br>
   <input type="text" name="comments" size="100" maxlength="250" >
   </p>
   <p>Send job description, questionnaire, applications, etc: <br>
   <input type="file"  name="file_to_upload" size="20" maxlength="40" >
   </p>
   <p> Reply to: <br>
   <input type="text" name="email" size="30" maxlength = 50 >
   </p>
 
   <input type="hidden" name="order" value="subject,comments,email,file_to_upload"> 
   <input type="submit" name="submit" value="Submit Now" >
   <input type="reset" name="reset" value="Reset" > 
 
<!--
   <input type="hidden" name="thankyou_url" value="http://www.bkelly.ws/test/">
-->
<?php $php_comment = $_POST["comment"]; ?>
Welcome <?php echo $_POST["comments"]; ?>.<br />
</form>
That is hard to read so here are the two statements I ask you to evaluate:

Code:
<?php $php_comment = $_POST["comment"]; ?>
Welcome <?php echo $_POST["comments"]; ?>.<br />
Will the first one get the data from the form and put it in the php variable named $php_comment?

When I click on the submit button, I get the following error message:

Code:
 <H1>Submission Error
Code:
]</H1>
 
Thank you for taking the time to submit your information. Unfortunately, we encountered an error during processing. Our servers were unable to determine the origin of the submission and did not receive your information. 
 
 
 
Potential Causes
  • If you are using Norton Internet Security or Norton Personal Firewall, please read Passing Referrer Instructions.
  • Zone Alarm Pro users, please enable referers. Open the options and uncheck the Remove Private Header information in the Cookies tab.
  • In Opera, open the preferences and choose Privacy. Check the box to enable referrer logging.
  • Some hardware proxy servers or firewalls may also remove or remove your referer. Check with your hardware manufacturer for technical support.
If you continue to experience issues, please contact the Web site's owner for further assistance.
What have I done wrong?
Maybe this is an HTML question.
bkelly is offline
Reply With Quote
View Public Profile
 
Old 10-27-2008, 09:08 PM Re: php email, getting html field variables
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Has the form been submitted at this point? Here is a simplified example of how to retrieve user input via a form:
Code:
 **<form action="test.php" method="post">
 **<input type="text" name="comments" />
 **<input type="submit" />
 **</form>
 **
PHP Code:
 **<?php
 
**//test.php
 
**$comments $_POST['comments'];
 **echo 
$comments;
 *
?>
 **
Notice that there are two distinct files here. Your original form is stored in one file and then your php code for handling that form is in another file (I called it test.php).

I don't know where those * are coming from. For some reason after I edited my post they just keep reappearing after I delete them. Weird.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 10-27-2008 at 09:11 PM.. Reason: spelling and I don't get along
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-28-2008, 02:27 PM Re: php email, getting html field variables
Average Talker

Posts: 25
Trades: 0
nullpointer wrote:

Code:
 
**<?php
**//test.php
**$comments = $_POST['comments'];
**echo $comments;
*?>
 **
I now have a simple version working. Thanks for the help.


Code:
$comments = $_POST['comments'];

on the left is a receiving variable, on the right is a function that provides the value to be put in the variable. In this context, POST is a verb meaning to put something, as is to post a letter or email. But here it gets, meaning to retrieve something. It looks to me that the meanings of POST and GET are reversed. This is rather disconcerting.

But more important, here are a couple of print statements I used:
Code:
print( "variable email_subject contains $email_subject \n" );
print( "variable email_body    contains $email_body \n" );
The newline ( backslash n ) has no effect. What do I need to do to get the two print statements on different lines. I tried inserting the html code of <br> and it blew away the entire page. (Meaning the page displayed as blank until I removed the <br>.) What is going on here?
bkelly is offline
Reply With Quote
View Public Profile
 
Old 10-28-2008, 05:20 PM Re: php email, getting html field variables
Average Talker

Posts: 25
Trades: 0
Regarding printing a new line, this just occurred to me:

Code:
print( "email_to contains  $email_to <br>" );

It works, php seems to put <br> in the page and sends it to the client. I am using MS IE. Any thoughts as to if there are any bad side effects or compatibility issues?
bkelly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php email, getting html field variables
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.41163 seconds with 12 queries