TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Tips & Tricks (http://www.talkphp.com/tips-tricks/)
-   -   Form Processing (http://www.talkphp.com/tips-tricks/13-form-processing.html)

William 04-10-2005 12:58 AM

Form Processing
 
Someone recently posted to make a Form Processing script so people would know how to use forms with there scripts.

Quote:

Originally Posted by Danny Needs Help
Form Processing/Mailing would be a good first tutorial :).

Well here you go. First of all you need to know a little HTML so you know how to make forms. Then you make you form. For instance:

<html>
<head>
<title>Form Processor</title>
</head>
<body>

FORM HTML
Code:

<form action='something.php' method='post'>

<table cellpadding='0' cellspacing='0'>
        <tr>
                <td>
                        <input type='text' name='VARIABLE_NAME' />
                </td>
        </tr>
        <tr>
                <td>
                        <input type='submit' value='Process Data' />
                </td>
        </tr>
</table>

</form>

</body>
</html>

something.php
PHP Code:

<?php

echo $_POST['VARIABLE_NAME'];

?>

There... Now you are wondering how does that work. Whatever you make the name of the form the value makes the variable set on the next page. I added $_POST[''] around the variable so it knew to get the data from a method on named post. in <form we added method='post' you can make it method='get' also. Which basically means you put $_GET[''], the difference is post is run hidden. Get puts all the variables in the url and gets the data from the url in other words for sites that have something.php?id=61102 to get the id you use $_GET['id'] it is just 2 different ways of putting the data to the next page. Most people like the post way to hide data like passwords but others like to show it to make there URL look cooler plus so people can send the url to a friend and it will automatically process the data. For instance if you made a script that calculated just using url you could make a file like:

calculator.php
PHP Code:

<?php

echo $_GET['data'];

?>

Then all you have to do is go to calculator.php and in url put: calculator.php?data=5+5-8*1/8 which will output: 0.25 on the page.
now to go back to the old method "post" you could make a form and on the page make a text box called "to" and someone put there eMail address there.Now on the page that the form sends the data to
just make it print $to and it will print what they typed. Now if you wanted to use what I said on the mail() tutorial you could do something like make a html
form then make the names... to, subject, body. then on the next page type: mail($to, $subject, $body, "From: My Feedback"); and you just made a feedback. Now
your probably wondering how does the html file know where to send the data. Well just change action='' in the <form> to the address of the PHP file and away you go.
Good luck!

AlEast 04-10-2005 01:38 AM

Can you update with register globals off since this will be the desired setting in the php.ini

CreativeLogic 04-10-2005 02:00 AM

There will need to be a few changes to this also. Once the tutorial section is updated we'll move it to a new area. Update it as AlEasy suggested and once the tutorial code is completed I'll either move it there or you can.

William 04-11-2005 02:00 AM

I just fixed the tutorial, Thanks for finding the bug. I do that for all my codes but I didn't wanna make it anymore harder for people that are just starting out. I forgot about the problem if register globals were off.

CreativeLogic 04-11-2005 02:07 AM

Either way, thanks for fixing it!

William 04-11-2005 02:10 AM

No problem.

Veolus 04-15-2005 12:49 AM

That's exactly what i have been looking for, the past few days.

Thanks for sharing this tutorial with us :)

edmarriner 04-16-2005 01:34 PM

very nice :D
keep them cooming !!!!!

ed

alegend 04-17-2005 03:24 PM

Thanks!
I been looking for something like this, since I kept getting errors when I tried writing one. Hope to see more.


All times are GMT. The time now is 04:49 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0