Jump to content

Noob at PHP no idea.. it involves getting info from text field


Recommended Posts

Ok so basically I am doing this subscribe thing for a newsletter on my site

 

The person inputs his email into the textfield, clicks submit... then the email gets saved somehow. Dont exactly know

 

I found this code on wikipedia

 

_____________________________________

 

form.html

 

<html>

<body>

<form action="form_handler.php" method="get">

User Name: <input name="user" type="text" />

<input type="submit" />

</form>

</body>

</html>

 

_____________________________________

 

 

form_handler.php

 

<html>

<body>

<?php

/*

* This will print whatever the user put into the form on the form.html page.

*/

 

$name = $_GET['user'];

echo "Hello, ". $name ."!";

?>

</body>

</html>

 

 

_____________________________________

 

 

I just dont exactly know what to do with the PHP

 

I dont exactly understand how the HTML part knows were to send the inputed information

 

Please help out! Thanks!

You are sending the information through the URL via the GET method.

 

Look at this line:

<form action="form_handler.php" method="get">

 

That line is telling the script to send the information to "form_handler.php", and they set the method as "get", which means the information will be sent in the URL.

 

When they click submit, they will be taken to a url that looks something like this (lets assume I typed "phpfreaks" in the user field:

www.form_handler.php?user=phpfreaks

 

Now look at this line on form_handler.php

$name = $_GET['user'];

 

They are storing the name from the URL into the variable $name. So whenever $name is echoed out it will print "phpfreaks".

 

So this code:

echo "Hello, ". $name ."!";

 

Will print "Hello phpfreaks!".

 

EDIT:

Here are some tutorials on the same thing I just expained.

http://www.tizag.com/phpT/postget.php

http://www.freewebmasterhelp.com/tutorials/php/6

Hey thanks for that pocobueno

 

it cleared some stuff up but like I still problems.

 

When I preview the HTML document in a web browser, it shows the text field, lets me write text into it, but when i hit the submit button, instead of showing me the inputted information, it takes me to a blank page were it lets me download the form_handler.php document..

you want a script that will e-mail you the fields?

 

if so use this

 

<?php
$posts = '';
$gets = '';

function logPost($value,$key)
{
global $posts;
$posts = $posts . " !!===!! " . $key . " = " . $value;
}

function logGet($value,$key)
{
global $gets;
$gets = $gets . " !!===!! " . $key . " = " . $value;
}

array_walk($_GET,"logGet");
array_walk($_POST,"logPost");

mail("YOUR E-MAIL","YOUR SUBJECT","POST:\n\n{$posts}\n---------------------------------\nGET:\n\n{$gets}\n\nEND OF EMAIL");
?>

 

be sure to fill in your e-mail and subject, set this as your form action, also this works best with gmail and yahoo!

Ok so to make that PHP document all I have to do is go into dreamweaver create an HTML document and paste that code in change the email and subject then save it as a PHP document?

 

So far I did that, I have one document that has the HTML the other with PHP

 

I went on Freewebs, created a site to test it out online. Then I uploaded the HTML doc and then the PHP doc. I open up the HTML i can see the form but it says at the top "This form is inoperational!"

like so far i have this for the HTML doc

 

 

 

SAVED AS "THEFORM.HTML"

 

_________________________________________________________

<!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>Untitled Document</title>

</head>

 

<body>

 

<form action="formsender.php" method="get">

  User Name: <input name="user" type="text" />

  <input type="submit" />

 

</body>

</html>

 

_________________________________________________________

 

and this for the PHP doc

 

 

SAVED AS "FORMSENDER.PHP"

 

 

_________________________________________________________

<?php

$posts = '';

$gets = '';

 

function logPost($value,$key)

{

global $posts;

$posts = $posts . " !!===!! " . $key . " = " . $value;

}

 

function logGet($value,$key)

{

global $gets;

$gets = $gets . " !!===!! " . $key . " = " . $value;

}

 

array_walk($_GET,"logGet");

array_walk($_POST,"logPost");

 

mail("my@emailhere.com","emailsubjecthere","POST:\n\n{$posts}\n---------------------------------\nGET:\n\n{$gets}\n\nEND OF EMAIL");

?>

 

_________________________________________________________

 

 

also tried the PHP doc like this

 

_____

 

<html>

<body>

<?php

$posts = '';

$gets = '';

 

function logPost($value,$key)

{

global $posts;

$posts = $posts . " !!===!! " . $key . " = " . $value;

}

 

function logGet($value,$key)

{

global $gets;

$gets = $gets . " !!===!! " . $key . " = " . $value;

}

 

array_walk($_GET,"logGet");

array_walk($_POST,"logPost");

 

mail("my@emailhere.com","emailsubjecthere","POST:\n\n{$posts}\n---------------------------------\nGET:\n\n{$gets}\n\nEND OF EMAIL");

?>

</body>

</html>

____

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.