Simple form data not working - html

I'm trying to upload an image and send it over to a server using a very basic form in HTML. Here is my code:
<form action="/api/addCategory" enctype="multipart/form-data" method="post">
<input type="hidden" name="name" value="test">
<input type="file" name="file" />
<input type="submit" value="Submit">
</form>
However when I click the button nothing happens (the server doesn't get any requests). The strange thing is I'm using an almost identical version of this code somewhere else in my project and it's working completely fine. What am I missing here?

Try like this ! Use any server side language like php.
<form action="/api/addCategory" enctype="multipart/form-data" method="post">
<input type="hidden" name="name" value="test">
<input type="file" name="file" />
<input type="submit" value="Submit">
<input class="fileattach" type="file" placeholder="upload" name="attachment" required><br></input>
</form>

Related

How to upload file in html?

How to upload a file in simple html? What all tags must be used?
<form action="/action_page.php">
<input name="pic" accept="image/*">
<input type="submit">
</form>
<form action="/action_page.php" method="post" enctype="multipart/form-data">
<input type="file" name="pic" id="image">
<input type="submit" name="submit">
</form>
you need a form with method POST & enctype multipart/form-data
you need a input type file to add your file
you need a button to submit. (you can submit without it too... using jQuery)
You need to do 2 changes.
<form action="/action_page.php" method="post" enctype="multipart/form-data">
Secondly, the field tag
<input type="file" name="pic" accept="image/*">

How can I make a submit button using html for several form action?

Can I use just a single <input type="submit" value="submit"> but for several form actions ...
Say if I type
<form id="form1" action="action1.py" method="get">
<input type="text" name="name">
</form>
<form id="form2" action="action2.py" method="get">
<input type="text" name="random">
<form>
then I want to use just a single <input type="submit" value="submit" or if there is another way to do it? Can anyone please explain me how to do it?

passing information in an form? confused with some of the examples on SO

I need to pass this so a hardware engineer can do his work but it's not working. Any suggestions?
http://wfbscd13.cadence.com/cgi-bin/motd.cgi?msg=3&cmd=replace&text="
Here is my code...
<div class="messageform">
<fieldset>
<legend>Title 1</legend>
<form action=http://wfbscd13.cadence.com/cgi-bin/motd.cgi?msg=1&cmd=replace&text=" method="post">
<label for="mestext1"></label>
<input type="text" size="100" maxlength="80">
<div class="floatright">Titles can be up to 80 Characters... upload file if beyond 80 chars &nbsp<input type="submit" name="button1" id="button1" value="Replace"></div><br>
I thought I was good on this code but it's not working right, any ideas? Did I miss something?
Better like this:
<div class="messageform">
<fieldset>
<legend>Title 1</legend>
<form action="http://wfbscd13.cadence.com/cgi-bin/motd.cgi" method="GET">
<input type="hidden" name="msg" value="1">
<input type="hidden" name="cmd" value="replace">
<label for="mestext1"></label>
<input type="text" id="mestext1"" name="text" size="100" maxlength="80">
<div class="floatright">Titles can be up to 80 Characters... upload file if beyond 80 chars
<input type="submit" name="button1" id="button1" value="Replace">
</div>
</form>
</fieldset>
</div>
You need to be more careful with closing quotes and tags.
If a URL has a '?' in it, it probably means they want it as a GET not a POST.
Use hidden variables for the fixed params.
Don't repeat the text param.
The for of a <label> needs to point to the id of a tag.
If this is your entire code, then its not working probably because the code is not well-formed , i.e. there are places where you have missed to close the tags.

How to set button's label without changing value in post

I've got this code in html:
<form action="/login/" method="post">
<input type="text" name="login">
<input type="text" name="pass">
<input type="submit" value="login" name="type" >
<input type="submit" value="register" name="type" >
</form>
When I submit this form it sends a get request with the value of the field of the button clicked. However I want to change the label of the button without changing the value sent in get. Is it possible or not?
Use a button element:
<button type="submit" name="type" value="register">Sign up for an account</button>
Note that old IE has problems with this.

Two submit buttons

I have two forms on a same page and I have two submit buttons...so how do I check if the user filled out the first form before clicking the submit button on second form? The first form posts the data to php page which presents on a same page as the html and the second form sends the data to another PHP page with thank you message....I mean how do force the user to finish the first form before clicking the submit button on the second form? if the user hits the submit button on the second form, the form directs to thank you page with out checking if the user finished the first form..how do I stop that?
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="submited" value="true" />
<label for="file">Choose Photo:</label>
<input type="file" name="file" onchange="file_selected = true;" required>
<input type="submit" value="Submit" name="submit">
</form>
<form action="Send.php" method="post">
First Name:<input type="text" name="fname" required><br>
Last Name:<input type="text" name="lname" required><br>
Choose Username:<input type="text" name="username" required><br>
Age:<input type="text" name="age" required><br>
<input type="submit" value="Submit" name="submit">
</form>
You can change the name field and then access the value on the server side.
For example:
<input type="submit" value="Submit" name="submitOne" />
If you're using php you could use something like this:
if(isset($_POST['submitOne'])){ /* first one pressed */ }
There are also some other options like using jQuery or javascript to validate first.
Try: http://bassistance.de/jquery-plugins/jquery-plugin-validation/