Jump to content

Some Form Handling Advice Needed!


BigNaz

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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.