Jump to content

Recommended Posts

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 :P

 

//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))

Link to comment
https://forums.phpfreaks.com/topic/183729-php-form-to-variable/
Share on other sites

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']; ?>

Link to comment
https://forums.phpfreaks.com/topic/183729-php-form-to-variable/#findComment-969737
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/183729-php-form-to-variable/#findComment-969744
Share on other sites

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.