BigNaz Posted August 27, 2007 Share Posted August 27, 2007 Hi folks, a quite pointer required... (sorry if this is a tired subject!) I have created a 'registration' form, with some basic verification procedures including a duplicate username check and double entry passwords etc. This all work fine and the database updates correctly and emails are sent and all that good stuff, however... I am now trying to make the script remember input values for use if the form fails, such as a 'passwords do not match' fail. The form is re-displayed to the user, and I would like any data already input to be filled in. I have tried using... (from within a html form decleration) <input type="text" name="username" maxlength="20" size="25" <?php if(isset($_POST['username'])){echo "value='" . $_POST['username'] . "'";}?>> But the field is empty when the form is displayed after a forced fail!! Am I that far off? Where am I going wrong with this one? Regards, BigNaz Quote Link to comment https://forums.phpfreaks.com/topic/66848-some-form-handling-advice-needed/ Share on other sites More sharing options...
matthewhaworth Posted August 27, 2007 Share Posted August 27, 2007 Set the values at the top of the page.. ... $name = $_GET['name'] ... etc. Then <input type="text" name="name" value="<?php echo $name; ?>"> Assuming the form targets the page it's on. Quote Link to comment https://forums.phpfreaks.com/topic/66848-some-form-handling-advice-needed/#findComment-335108 Share on other sites More sharing options...
BigNaz Posted August 27, 2007 Author Share Posted August 27, 2007 I tried that, but it appears that for some reason the variable is not being passed from the form?? The page checks for submit using if(isset($_POST['submit'])){ I thought the value from an input text field called 'username' would work the same, however I keep getting undefined variable notices!? Any other suggestions? Regards, BigNaz Quote Link to comment https://forums.phpfreaks.com/topic/66848-some-form-handling-advice-needed/#findComment-335119 Share on other sites More sharing options...
pl_harish Posted August 27, 2007 Share Posted August 27, 2007 Firstly, Try to debug by doing print_r($_POST) at the beginning of the form processing page to chk if values are passed. if the values are infact not passed, make sure your form and elements have the name attribute. this is important on many browsers unlike IE where id attribute would do. That should help. Secondly, instead of <input type="text" name="name" value="<?php echo $name; ?>"> best practice is <input type="text" name="name" value="<?= $name; ?>"> also best practice is set your php.ini such that you can use just <? why use 3 chars in excess every time.. if you are using a hosting company, then probably they have already done that and only your style gotta change. regards, Harish www.harishpalaniappan.com www.floresense.com Quote Link to comment https://forums.phpfreaks.com/topic/66848-some-form-handling-advice-needed/#findComment-335162 Share on other sites More sharing options...
AndyB Posted August 27, 2007 Share Posted August 27, 2007 instead of <input type="text" name="name" value="<?php echo $name; ?>"> best practice is <input type="text" name="name" value="<?= $name; ?>"> Definitely not best practice! That will fail on any server where short tags are not enabled. Best practice is to write code that runs on any server configuration. Quote Link to comment https://forums.phpfreaks.com/topic/66848-some-form-handling-advice-needed/#findComment-335167 Share on other sites More sharing options...
pl_harish Posted August 27, 2007 Share Posted August 27, 2007 while i agree to that.. i assume, if you hire hosting, you should look for atleast the basic things that you need, rather than "write code that works on ANY server". shouldn't we be looking at best practices as that is best for code rather than best for server hosting companies. if some company doesn't support fopen but only curl, does that mean fopen is not best practice...or curl is better than fopen?? yes, if short tags are not supported on your server, it is a stupid suggestion.. but having <? tag enabled, <?= tag enabled, having .php extension enabled (rather than just .php3/.php4), etc, are very basic items that any valuable hosting should be doing if we are even going to put up a php website. regards, Harish. www.floresense.com www.harishpalaniappan.com Quote Link to comment https://forums.phpfreaks.com/topic/66848-some-form-handling-advice-needed/#findComment-335366 Share on other sites More sharing options...
AndyB Posted August 27, 2007 Share Posted August 27, 2007 All I can say is we differ on what a 'best practice' actually is. Apparently yours is one where you can avoid a bit of typing at the expense of having to edit every script when your client already provides hosting, and mine is providing scripts that work without needing to be edited. Each to his own. Quote Link to comment https://forums.phpfreaks.com/topic/66848-some-form-handling-advice-needed/#findComment-335435 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.