Posting file from form to another page - php

<form id="form1" name="form1" align="center" action="http://www.test.org/add-listing/?listing_type_id=test" method="POST" enctype="multipart/form-data">
<input type="file" Value="UPLOAD RESUME" id="UploadResume" name="UploadResume" >
<br>
<input type="submit" Value="Upload Resume" id="SubmitResume" >
</form>
I am trying to post form data to another page; however, it seems like it is trying to go to
http://www.test.org/add-listing
instead of
http://www.test.org/add-listing/?listing_type_id=test
is there something i'm missing here?

You form method is POST so you can't pass data through GET (URL)
If you want to pass that value, you can use hidden inputs :
<input type="hidden" name="listing_type_id" value="test">
You will be able to get it on the other side with $_POST["listing_type_id"]

Related

how can I get the value of a input field using PHP if there are two forms on the page both of POST method

I want to get the value of an <input> field using PHP.
There are two forms on my page both of POST method.
<form method="POST">
<input type="text" name="first">
<input type="submit" name="submit" value="submit">
</form>
<form method="POST">
<input type="text" name="second">
<input type="submit" name="submit1" value="Post">
</form>
How do I get the value of the second input field? Even though if I use $_POST['second'] it shows me an error:
Undefined index: 'second'
The W3C specs define that an input can be associated to only one form. It is a sign of bad design when you need to have multiple forms and the backend has to know which data is present in other forms.
The <form> element can contain arbitrary element structures like tables, it can even contain the entire document body content. You should hardly need multiple forms.
A common use-case is to have multiple submit buttons having the same name instead. Only the pressed button will be part of the form data.
<form method="post">
<input type="text" name="text_input">
<button type="submit" name="action" value="add">submit</button>
<button type="submit" name="action" value="update">submit</button>
<button type="submit" name="action" value="delete">submit</button>
</form>
Again, do not do that, however, if you really want to share a field across multiple forms for some reason, this can only be done by javascript intercepting the form submit event. This will not work when scripts are disabled by the user.
document.querySelectorAll('form').forEach(e => {
e.addEventListener('submit', function() {
document.querySelectorAll('.multi-form-input').forEach(e => e.setAttribute('form', this.id));
})
})
<input class="multi-form-input" name="common_input" type="text">
<form id="form-1" method="post">
<button type="submit" name="action" value="1">submit</button>
</form>
<form id="form-2" method="post">
<button type="submit" name="action" value="2">submit</button>
</form>

Php get method resseting url

i am submitting form using get method to a url which already contain parameter like
localhost/myfile.php?section=console
my form code is
<form method="GET" action="<?=basename($_SERVER['PHP_SELF'])?>/section=console">
<input type="text" name="cmd" />
<input type="submit" value="execute" />
</form>
when i submit this data through post type it submit data then it submit like myfile.php?cmd=blahblah
but i want to submit it to myfile.php?section=console&cmd=blahblah.
i can do this by using hidden field but i am insearch of other better way
Simply add a hidden field into your form
<input type="hidden" name="section" value="console">
If you are not interested in using hidden fields then rewrite your form like this
<form method="GET" action="<?php basename($_SERVER['PHP_SELF']) ?>/?section=console">
You should use a hidden input within your form
<form method="GET" action="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="hidden" name="section" value="console">
<input type="text" name="cmd">
<input type="submit" value="execute">
</form>

using one input file with two different form

Is there a way to using a input file with two different form?
I need only one input file and have to post this file to .php page depending of user selection.
Thanks.
<label for="file">Photo:</label>
<input type="file" name="file" id="file">
<form action="c.php" method="post" enctype="multipart/form-data" >
<input type="submit" name="submit" value="C">
</form>
<form action="d.php" method="post" enctype="multipart/form-data">
<input type="submit" name="submit" value="D">
</form>
You could redirect to page cd.php which includes c.php or d.php depending on the value C or D

Old data gets wiped from POST when I use GET

So I am having an issue. I used POST to send data to a new page. I use get to send data to a function but it seems the POST data get wiped. Here some code to help explain.
POST CODE to send to form vieworder (works perfect!)
<form method="post" action="vieworder.php">
<input type="hidden" name ="user_id" value="<?php echo $_SESSION['user_id']; ?>">
<input type="hidden" name ="id" value="<?php echo $data1[$x]['id']; ?>">
<input type="submit" name="submit" value="View"> </td>
</form>
So on the vieworder page I want used to be able to update the data using this form.
This form works as well except i need that value "id" from the orginal post. It works and the "id"has the data until I use this form.
<form name="approveform" method="get" action="">
Index Number*: <input type="text" name="IndexNum">
<input type="submit" value="Approve" action="">
</form>
I would also prefer to use the POST method but using GET was my first solution to no deleting the data from POST.
Anyways I then just send the data to a function to update two fields.
Any way to get correct the code?
<?php
$id=$_POST['user_id'];
?>
<form name="approveform" method="get" action="">
Index Number*: <input type="text" name="IndexNum">
<input type='hidden' value='<?php echo $id;?>'>
<input type="submit" value="Approve" action="">
</form>

How to send iframe id/name to a php file?

I have a iframe with a name, in this case an email address that changes from users.
I need to deal with this var:
<iframe name="asd#asd.lol" src="index.html">
index.html is a simple data form like this:
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>
I need to pass the value "asd#asd.lol" to the "upload.php" file.
Is this possible?
Is it possible for you to add a querystring parameter into the index.html file?
So:
<iframe name="asd#asd.lol" src="index.html?email=asd#asd.lol">
Then in the index.html file set a hidden variable:
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="hidden" name="email" id="email" value="">
<input type="submit" value="Upload">
</form>
If this is a plain HTML file you could set the value of the hidden field with some javascript.
Then use $_POST["email"] to get the email value out of the hidden field.
<form ENCTYPE="multipart/form-data" action="upload.php" method="POST" onsubmit='$(this).append('<input type="hidden" name="iframeEmail" value="'+$("iframe[src='index.html']").attr('name')+'">')'>
<p>Upload: <input type="file" name="file1"> <br /></p>
<input type="submit" value="Upload">
</form>
Try this out ,if it wont work ,than place the iFrame and ID and find it with the ID on jQuery Selector

Categories