Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html php retain form value

Tags:

html

forms

php

As the title says, i'm trying to retain the value submitted from a text form. so I thought the following simple code on the pre-process page would do the trick but the text box is still blank.

<form id="form1" name="form1" method="get" action="pre_process.php">
        <input name="q" type="text" value="<?php $_GET['q']; ?>" size="80"/>

Any suggestions?

Thanks

like image 973
shanahobo86 Avatar asked Jul 25 '26 23:07

shanahobo86


2 Answers

Try:

<input name="q" type="text" value="<?php echo $_GET['q']; ?>" size="80"/>

You need to echo the value out.

To avoid Notices you should use the isset function to check if the value was set

Your code should look like:

<input name="q" type="text" value="<?php echo isset($_GET['q']) ? $_GET['q'] : NULL; ?>" size="80"/>
like image 86
andrewsi Avatar answered Jul 28 '26 14:07

andrewsi


You forgot to call echo. Your code should read:

<?php echo $_GET['q']; ?>

like image 44
Rawkode Avatar answered Jul 28 '26 12:07

Rawkode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!