Jump to content

Load Upload Form to Itself?


doubledee

Recommended Posts

In the past I always combine my PHP Form Processing Code with my HTML Forms in one script, and when the User clicks "Submit", the Form/Page reloads itself.

 

Is it possible to load an Upload Form to itself?

 

Something like this...

<form enctype="multipart/form-data" action="" method="post">

 

 

 

Debbie

 

 

Link to comment
Share on other sites

Yes, it's possible. And from my point of view it's the preferred method. Because if something is wrong in the input data, I can show all data entered and give to user a chance to change it.

When data is correct I can process it and do anything I wish. If I need, I can root to another script or do something here, in this script.

Link to comment
Share on other sites

You can omit the action and it will default to itself, however most people will explicitly set the action programmatically using a variable.  Of the available methods, there is PHP_SELF, REQUEST_URI and SCRIPT_NAME.  I'll leave it to you to investigate the differences between those options, but one that is frequently the best choice is to use:

 

</pre>
<form enctype="multipart/form-data" action="<?php%20echo%20%24_SERVER%5B'SCRIPT_NAME'%5D;%20?>" method="post">
<

Link to comment
Share on other sites

Yes, it's possible. And from my point of view it's the preferred method. Because if something is wrong in the input data, I can show all data entered and give to user a chance to change it.

When data is correct I can process it and do anything I wish. If I need, I can root to another script or do something here, in this script.

 

I like to do that too.

 

 

Debbie

 

Link to comment
Share on other sites

You can omit the action and it will default to itself, however most people will explicitly set the action programmatically using a variable.  Of the available methods, there is PHP_SELF, REQUEST_URI and SCRIPT_NAME.  I'll leave it to you to investigate the differences between those options, but one that is frequently the best choice is to use:

 

<form enctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">

 

Why can't I just do...

action=""

 

That is what I have always done in the past.

 

 

Debbie

Link to comment
Share on other sites

I said you could omit it, by which I meant you could leave it empty or not include the action at all.  They are essentially the same, but as far as picking one or the other, using action="" is probably better, as it will validate while omitting the action entirely probably will not.

 

The main reason not to use action="" is that it triggers "magic behavior" in the browsers.  All the main web browsers handle this situation fine, and redirect, however, there are fringe browsers used on some mobile phones that are known not to behave in the way you desire.  So it is better to explicitly provide a uri, if you want to maximize your compatibility across all user agents.  Whether you care about that or not, is up to you.

Link to comment
Share on other sites

I said you could omit it, by which I meant you could leave it empty or not include the action at all.  They are essentially the same, but as far as picking one or the other, using action="" is probably better, as it will validate while omitting the action entirely probably will not.

 

The main reason not to use action="" is that it triggers "magic behavior" in the browsers.  All the main web browsers handle this situation fine, and redirect, however, there are fringe browsers used on some mobile phones that are known not to behave in the way you desire.  So it is better to explicitly provide a uri, if you want to maximize your compatibility across all user agents.  Whether you care about that or not, is up to you.

 

Yes, I want the best code I can write.

 

So it sounds like you think this is best...

action="<?php echo $_SERVER['SCRIPT_NAME']; ?>"

 

(I know that PHP_SELF is a no-no!)

 

 

Debbie

 

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.