I have wired problem.
I have this input inside my form
<form action="..." method="post">
<div class="radio">
<input class="check-with-label" type="checkbox" id="c1-img0" name="img;http://img01.cp.aliimg.com/bao/uploaded/i1/1610868057/T25iVOXaNeXXXXXXXX_!!1610868057.jpg">
<label class="label-for-check" for="c1-img0"><img src="http://img01.cp.aliimg.com/bao/uploaded/i1/1610868057/T25iVOXaNeXXXXXXXX_!!1610868057.jpg"></label>
</div>
</form>
But in my php file i get this variable when i call print_r($_POST);
[img;http://img01_cp_aliimg_com/bao/uploaded/i1/1610868057/T25iVOXaNeXXXXXXXX_!!1610868057_jpg] => on
Like you see I lose all dots in my link in PHP file.
Orginal: img;http://img01.cp.aliimg.com/bao/uploaded/i1/1610868057/T25iVOXaNeXXXXXXXX_!!1610868057.jpg
Recived: img;http://img01_cp_aliimg_com/bao/uploaded/i1/1610868057/T25iVOXaNeXXXXXXXX_!!1610868057_jpg
You have put image link in name attribute instead of value.
Try
<form action="" method="post">
<div class="radio">
<input class="check-with-label" type="checkbox" id="c1-img0" name="image" value="img;http://img01.cp.aliimg.com/bao/uploaded/i1/1610868057/T25iVOXaNeXXXXXXXX_!!1610868057.jpg">
<label class="label-for-check" for="c1-img0"><img src="http://img01.cp.aliimg.com/bao/uploaded/i1/1610868057/T25iVOXaNeXXXXXXXX_!!1610868057.jpg"></label>
</div>
<input type="submit" value="submit">
</form>
<?php
var_dump($_POST);
?>
Related
This question already has answers here:
When submitting a GET form, the query string is removed from the action URL
(13 answers)
Closed 1 year ago.
I'm trying to make a filter using a MySQL database and PHP for a school project, but whenever I press my filter button, it doesn't execute the action so the querystring is not updated.
The reason it's referring to my homepage is because of this block code:
if (empty($_GET['page'])) {
$_GET['page'] = 'home';
}
if (empty($routes[$_GET['page']])) {
header('Location: index.php');
exit();
}
This is when there is no $GET['page'] passed, and it will just refer to my homepage.
So the problem probably lies with my form action, which is clearly correct: action="index.php?page=agenda"
<form class="filter_form" method="get" action="index.php?page=agenda">
<div class="location">
<p class="filter_by">filter by:</p>
<label for="location">location</label>
<select name="location" id="location">
<option value="all">-- Locations --</option>
<?php foreach($locations as $location): ?>
<option value="<?php echo $location['location']; ?>"
<?php
if(!empty($_GET['location'])){
if($_GET['location'] == $location['location']){
echo ' selected';
}
}
?>
>
<?php echo $location['location']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="checker_wrapper">
<div>
<input type="checkbox" name="check1" id="check1">
<label for="check1">skills only</label>
</div>
<div class="bottom_row">
<input type="radio" name="group" id="radio1">
<label for="radio1">day</label>
</div>
</div>
<div class="radio_wrapper">
<div>
<input type="checkbox" name="check2" id="check2">
<label for="check1">in group</label>
</div>
<div class="bottom_row">
<input type="radio" name="group" id="radio2">
<label for="radio2">evening</label>
</div>
</div>
<input class="button filter_button" type="submit" value="filter" />
</form>
When I press the filter button, I'm in the homepage and the querystring is like this: index.php?location=all, so the $_GET[location] for my project works. It's just not adding the correct page in the string.
Your form is overriding the query string parameters in your action attribute.
Instead of putting the query string in the action, add a hidden field
<form class="filter_form" method="get" action="index.php">
<!-- ... the rest of your form code -->
<input class="button filter_button" type="submit" value="filter" />
<input type="hidden" name="page" id="page" value="agenda" />
</form>
Related post: submitting a GET form with query string params and hidden params disappear
You should use a hidden input element in your form rather than adding your parameters in the URL:
<input id="page" name="page" type="hidden" value="agenda">
You should add a hidden input field into the form. Instead attach it into the action string,
<input type="hidden" name="page" value="agenda" />
Add a hidden field:
<input type="hidden" name="page" value="agenda" />
The get parameter in your action is overruled by the method "GET".
I have a PHP script where I upload a *.txt file and I use the information inside that *.txt file to do some things.
The form for uploading this text file:
<form method="post" action="index.php" enctype="multipart/form-data">
<input class="file-choice" name="file" type="file" />
<input class="upload-button" type="submit" value="Upload Bestand" name="start" />
</form>
After I worked with this file I want to give the visitor a choice to change some things, with their own input.
The form for the user input:
<form method="post">
<div class="input-block">
<b>Rechts naar links:</b> <br>
<input type="radio" name="horizontaal" value="rl-aan">Aan
<input type="radio" name="horizontaal" value="rl-uit">Uit<br>
</div>
<div class="input-block">
<b>Verticaal:</b> <br>
<input type="radio" name="verticaal" value="ver-aan">Aan
<input type="radio" name="verticaal" value="ver-uit">Uit<br>
</div>
<div class="input-block">
<b>Diagonaal:</b> <br>
<input type="radio" name="diagonaal" value="dia-aan">Aan
<input type="radio" name="diagonaal" value="dia-uit">Uit<br>
</div>
<input type="submit" name="test" />
</form>
My problem is when I press the submit button of either the file upload or user input the other form is retested. So for example if I press the submit for the user input, the file that I uploaded before is gone.
I tried changing the method from POST to GET and I've tried to give both the submits the same name but both did not work.
Any suggestions?
I figured it out.
I had to work with sesions to save the needed variables from reading the file and add the name of the user input submit to all the scripts except the read script from the file.
Give different form id and submit button id .
I have two buttons in my form, one is for answer a question and the other is for copy the question.
<div id="question">
<?php echo($question->content) ?>
</div>
<form action="script.php" method="GET" id="question">
<input type="text" name="question">
<button id="answer" onclick="document.getElementById('question').submit()">Answer the question</button>
<button id="copy" onclick="document.getElementById('question').submit()">Copy the question</button>
</form>
The URL of script.php look now like:
script.php?question=sometext
Now I want that when you click at the copy button the URL looks like this:
script.php?question=sometext©
And for the answer button:
script.php?question=sometext&answer
EDIT:
There are much answers where is said: "use <input type> instead of <button>"
The problem is that I can't use a input field as button because the button is outside my form. And I can't put it inside my form
What you can do is to use one hidden field and change it's name according to the pressed button. Something like the following:
<div id="question">
<?php echo($question->content) ?>
</div>
<form action="script.php" method="GET" id="question">
<input type="text" name="question">
<input id="action" type="hidden" name="" value="">
<button id="answer" onclick="document.getElementById('action').setAttribute('name','answer'); document.getElementById('question').submit()">Answer the question</button>
<button id="copy" onclick="document.getElementById('action').setAttribute('name','copy'); document.getElementById('question').submit()">Copy the question</button>
</form>
Although this would give you the result you want at the url, it would be more appropriate to have as the hidden's field name the "action" and to change it's value to "copy" or "answer" through javascript.
Try to make two forms, with a hidden input field with the values. Then you get the extra parametrt in your url when submitting
Change your form to the following
<form action="script.php" method="GET" id="question">
<input id="question" type="text" name="question">
<input id="answer" type="submit" name="answer" value="true">
<input id="copy" type="submit" name="copy" value="true">
</form>
url:
script.php?question=hello©=true
Then you can check
if(isset($_GET['answer']) && $_GET['answer']=="true"){
//answer action
}
if(isset($_GET['copy']) && $_GET['copy']=="true"){
//copy action
}
I have this problem when I'm using PHP5/HTML on Apache-Tomcat6.
Here's an example for one of the forms I use in my site:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
Whenever I add the 'enctype' attribute to any form; neither the $_FILES['image'] is returned nor the $_POST variables. As long as the 'enctype' is not there, everything (except for the file input of course) works as expected. Can any one guide me please?
You won't be able to post data with a method of get on your form.
In test.html:
<form enctype="multipart/form-data" method="post" action="hello.php" >
<label>Title* :</label>
<input type="text" name="title" />
<label>Image:</label>
<input type="file" name="image" /><br />
<input type="submit" value="Add"/>
</form>
In hello.php:
<?php
print_r($_POST);
print_r($_FILES);
Depending upon your server configuration, this will combine $_GET, $_POST, and $_COOKIE, but you'll still want to post with file inputs.
print_r($_REQUEST);
I have a form, like this
<form id="picuploadform" enctype="multipart/form-data" method="post" action="">
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" name="fileToUpload" id="fileToUpload" />
<input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
</div>
<div class="row" style="width:150px;">
<input type="submit" value="Upload" />
</div>
</form>
Which when I click the submit button I have PHP on this page to process it just fine. $_FILES for receiving file and $_POST for reading picssn that came with the hidden input. But due to problem with Jquery mobile I can't use submit or .submit() now. So I want to use
$.post('myphpfile.php', {picssn:$('#picssn').value(), file: $('#fileToUpload').xxxxxxxxxxxxxxxxx });
instead. But I have no idea how to grab the file out of that form and send it this way. Is there some method that can replace xxxxxxxxxxxxxx ? Thanks!
On your form element, you need to disable the ajax submit, and then fix your other code.
Try this:
<form id="picuploadform" enctype="multipart/form-data" method="post" action="#" data-ajax="false">
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" name="fileToUpload" id="fileToUpload" />
<input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
</div>
<div class="row" style="width:150px;">
<input type="submit" value="Upload" />
</div>
</form>
You cant upload directly via ajax. Check this perhaps:
http://blueimp.github.com/jQuery-File-Upload/ or uploadify.com