I need to use GET and POST by either having two forms or one form using GET and POST both in it.
I have this code:
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" /><input name="name" value="
<?php
$name = $_GET["name"];
echo $name
?>" type="hidden">
</form><br><br>
<?php
$name = $_GET["name"];
echo "Thanks for using File Fetchers, $name!";
?>
I need to get $name to upload.php using GET, but I need the file to be uploaded to upload.php
What can I do?
Thanks,
Alex
GET and POST in one form?
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: GET and POST in one form?
Stick the GET parameters inside the action attribute of the for, but keep the form's method attribute set to post:
Code: Select all
<form action="script.php?some=get¶meters=here" method="post">Re: GET and POST in one form?
Though not critical, it's a good idea to use urlencode() on the GET variables before you put them in the form.
Edit: This post was recovered from search engine cache.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Mon Jun 14, 2010 1:47 pm, edited 1 time in total.
Re: GET and POST in one form?
Could you give me an example of how this would be implemented in my code?
Thanks,
Alex
Thanks,
Alex
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: GET and POST in one form?
Code: Select all
<?php
$name = isset($_GET["name"])
? $_GET["name"] //If $_GET['name'] is there, use it
: "some default"; //Otherwise use this default
?>
<?php /* Add the name parameter back into the form action */ ?>
<form enctype="multipart/form-data" action="upload.php?name=<?php echo htmlspecialchars(urlencode($name)); ?>" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form><br><br>
<?php
echo "Thanks for using File Fetchers, $name!";
?>Re: GET and POST in one form?
Thanks! That helped. Could I send the name in a form (to me) and upload the file with upload.php? I mean, could I have two form functions in one page?