ille94 Posted December 2, 2009 Share Posted December 2, 2009 Hi! I have written a HTML-form code in DreamWeaver CS3 (in a PHP doc) and I really need it to work soon :/ I have a form: (<form name="form1" action="" method="post">) and inputs to it: (<input name="name" type="text" maxlength="11" />)... and I need that into a variable or what it's called... So when I type "Hello World" in that textbox... It will type "Hello World" outside the form in Dynamic Text... like: <p><b><?php $name ?></b></p> Then the text will be shown as (<p><b>Hello World</b></p>) And in an IMG src-code it will get the image called "Hello World" in that folder: <img src="img/<?php $name ?>.gif"> (If there WAS a picture called "Hello World.gif") Hope you understand my explaination here //Elias (The site I need the code to go to is: http://mypage.ath.cx/ ) (Under the text "Profile:" the "Nickname" text box will type whatever you type in to it (instant)) Quote Link to comment https://forums.phpfreaks.com/topic/183729-php-form-to-variable/ Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 When a form is submitted the values of the inputs on the form are stored in the $_POST array, it will store it using the name attribute of the input tag as the key for the array. So for example... <input type="text" name="flibble" /> // would be accessed using <?php echo $_POST['flibble']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/183729-php-form-to-variable/#findComment-969737 Share on other sites More sharing options...
KevinM1 Posted December 2, 2009 Share Posted December 2, 2009 Well, with forms, you need to supply them an action - a script which will process the data entered in the form. Given what you want to do, the action should be the same PHP file that contains your HTML form. It can be referenced like so: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> In order to obtain the values entered in the form, you'll need to use the correct superglobal array. These arrays are mapped to the different form methods, so there's a $_POST[] array and $_GET[] array. Example: <input type="text" name="name" /> Can be obtained with: $_POST['name']; Aside from that, since the form is essentially posting to itself, you should structure your page so the form handling (the PHP that processes the form data) occurs first, followed by the HTML. Quote Link to comment https://forums.phpfreaks.com/topic/183729-php-form-to-variable/#findComment-969744 Share on other sites More sharing options...
MisterWebz Posted December 2, 2009 Share Posted December 2, 2009 <html> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Name: <input type="text" name="name" /> <input type="submit" /> </form> <p><b><?php echo $_POST['name'] ?></b></p> </html> </body> Quote Link to comment https://forums.phpfreaks.com/topic/183729-php-form-to-variable/#findComment-969814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.