NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Link php


Joined: 06 Jan 2007
Posts: 19
Reply with quote
hey there. i am reading the book PHP for the world wide web 2nd edition by Larry Ullman and i am just getting to chapter 5. I have been able to read and understand and actually testing everything so far, but i have a question "maybe i still need to read more of the book for it,but i wanted to ask first".
Lets say i create a submition table, like i did following the book. i created handle_form.php and feedback. But when i go and fill the form, and i hit submit, it goes well and gives me the message from handle_form with submited details. But how to i get visitors to send me feedback and where does it go ??

Thanks guys,
View user's profileFind all posts by LuisMartinsSend private message


Joined: 30 Dec 2006
Posts: 9
Location: Germany
Reply with quote
Usually, when you create the form with <form action="your_script.php" method="post">, then your input is sent to the $_POST array in PHP. If you create it with method="get", therefore, it's in the $_GET array. The indices of both arrays are the values you have given by the name attribute in the input tag. E.g.

<form method="post" action="script.php">
<input name="textbox" type="text" />
<input name="btn" type="submit" value="Submit this form!" />
</form>

then the values of the textbox are written to $_POST["textbox"] when you click the submit button, and $_POST["btn"] is "Submit this form!".

For more information see the PHP manual at http://www.php.net/manual/en/language.variables.external.php . The PHP manual there is the official one and it can help you in most cases.
View user's profileFind all posts by rohiebSend private message


Joined: 06 Jan 2007
Posts: 19
Reply with quote
thanks for that.
i am new to this still, how do i get to $_POST["textbox"] ?
i uploaded this files to my web server.
View user's profileFind all posts by LuisMartinsSend private message
Veteran

Joined: 26 Dec 2006
Posts: 253
Location: Phoenix, AZ
Reply with quote
$_POST is a variable that's auto-created for you. Just do this:

<?php

$myTextboxContents = $_POST['textbox'];
echo $myTextboxContents;

?>

As rohieb said, see the docs.
View user's profileFind all posts by bobwilliamsSend private messageVisit poster's website


Joined: 06 Jan 2007
Posts: 19
Reply with quote
i have read it a few contents, i just am a lil confused right now. this code u gave me :
<?php

$myTextboxContents = $_POST['textbox'];
echo $myTextboxContents;

?>
do i manualy type it to my handle_post so i can see the posts sent ?
thanks again
View user's profileFind all posts by LuisMartinsSend private message
Veteran

Joined: 26 Dec 2006
Posts: 253
Location: Phoenix, AZ
Reply with quote
I'm not sure what handle_post is, as that's the first time you've mentioned it. Here's the deal. Say you have a form, perhaps the one roheib created, inside the file MyForm.html:

File MyForm.html:
Code:

<html>
<head></head>
<body>
   <form method="post" action="MyForm_action.php">
      <input name="textbox" type="text" />
      <input name="btn" type="submit" value="Submit this form!" />
</form>
</body>
</html>


Note that action attribute on the form field; that tells the browser where to send the form data when it's submitted. The method attribute tells the browser *how* to send the data; in this case, it's via POST. So you create the action file like so:

File MyForm_action.php:
Code:

<html>
<head></head>
<body>
   <?php
      $myTextboxContents = $_POST['textbox'];
      echo $myTextboxContents;
   ?>
</body>
</html>


So when the user submits the form on MyForm.html, the browser sends the form data to MyForm_action.php via POST. The little PHP script then pulls the data from the $_POST variable (which is where all form POST data is automatically deposited for you) and prints it out.

Hope this helps.
View user's profileFind all posts by bobwilliamsSend private messageVisit poster's website


Joined: 06 Jan 2007
Posts: 19
Reply with quote
this is the feedback :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Feedback Form</title>
</head>
<body>
Please complete this form to submit your feedback: <br />

<form action="handle_form.php"method="post">


Mr. <input type="radio" name="title" value="Mr." />
Mrs. <input type="radio" name="title" value="Mrs." />
Ms. <input type="radio" name="title" value="Ms." />
<br />
Name: <input type="text" name="name" size="20" />
<br />
Email Address: <input type="text" name="email" size="20" />
<br />
Response: <select name="response">
<option value="excellent">This is excellent.</option>
<option value="okay">This is okay.</option>
<option value="boring">This is boring.</option>
</select>
<br />
Comments: <textarea name="comments" rows="3" cols="30"></textarea>
<br />
<input type="submit" name="submit" value="Send My Feedback" />

</form>

<!-- Script 3.3 - feedback.html -->
</body>
</html>

and this is the handle_post

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Your Forum Posting</title>
</head>
<body>
<?php // Script 5.7 - handle_post.php

// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~ E_NOTICE);

//In case register_globals is disabled.
$first_name = trim ($_POST['first_name']);
$last_name = trim ($_POST['last_name']);
$posting = trim ($_POST['posting']);

// Create a name variable.
$name = $first_name . ' ' . $last_name;
$name = stripslashes ($name);
$posting = stripslashes ($posting);
// Take out the bad words.
$posting = str_replace ('.', 'XXXX', $posting);

// Change the capitalization of the name.
$name = ucwords (strtolower($name) );

// Print the message.
print "Thank you, $name, for your posting:<br />
<p>$posting</p>
<p>$post1</p>
<p>$post2</p>
";

// make a link to another page.
$email = urlencode ($name);
$email = urlencode ($_POST['email']);
print "Click <a href=\"thanks.php? name=$name&email=$email\">here</a> to continue.";

?>
</body>
</html>


i want to have the feedback sent to my email or to another page where i can read what people sent me.

thanks again
View user's profileFind all posts by LuisMartinsSend private message


Joined: 06 Jan 2007
Posts: 19
Reply with quote
ok, here's a little bit more detailed. i also tried the code u gave me.

this is the feedback

Please complete this form to submit your posting:

First Name: luis
Last Name: martins
Email Address: whatever@yahoo.com
Posting: this is a test.

i click post

and it goes to different page :

Thank you, Luis Martins, for your posting:

this is just a test.


Click here to continue.

and i click here and takes me to the last page :

Thank you, Luis Martins. We will contact you at the email given email@yahoo.com.

Now the thing is, where does the feedback go to? how do i go to receive them ?
i am sorry if i am a pain , its just that i want to move on reading the rest of the book and without knowing this little thing i cant.

thanks again
View user's profileFind all posts by LuisMartinsSend private message
Veteran

Joined: 26 Dec 2006
Posts: 253
Location: Phoenix, AZ
Reply with quote
Right now, it's not going anywhere. You're just pulling the information out and sending it back to the browser. If you want to e-mail yourself, you'll want to use the mail() function; see:

http://www.php.net/mail

You'll probably want to put all of your variables together to form the body of the message. For example:

$body = "You've received a form submission from $first_name $last_name, whose e-mail address is $email. They said: $posting.";

And then pass $body into mail().
View user's profileFind all posts by bobwilliamsSend private messageVisit poster's website
Link php
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic