Making a form look like bootstrap button - html

Hi guys so currently i have a simple button in bootstrap which looks like :
class="btn btn-success btn-block btnrec"
I then was trying to make my form buttons look like that, however its not working correctly , anyone know why?
My attempt so far:
<form action="" method="post" enctype="multipart/form-data">
<input class="btn btn-success btn-block btnrec" type="file" name="file">
<input class="btn btn-success btn-block btnrec"type="submit" name="submit">
</form>
As you can see, the submit was works fine, looks like the bootstrap button but the one above, which is the choose file "File not found" etc does not, this for me uploading a pic to the db, but just want to make the buttons look nice :0
Thanks
Tried this:
<form action="" method="post" enctype="multipart/form-data">
<a class='btn btn-primary' href='javascript:;'>
Choose File...
<input type="file" name ="file" style='position:absolute;z-index:2;top:0;left:0;filter: alpha(opacity=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";opacity:0;background-color:transparent;color:transparent;' name="file_source" size="40" onchange='$("#upload-file-info").html($(this).val());'>
</a>
<input class="btn btn-success btn-block btnrec"type="submit" name="submit">
</form>

Bootstrap distinguishes inputs based on their type. That way it knows to style a [type='text'] differently from a [type='submit']. In this case, Bootstrap doesn't have styling for input[type='file'] built in to the library.
This answer has roughly equivalent styling for that element that you can add yourself.

Following this links examples https://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3
<!-- support IE8 -->
<form action="" method="post" enctype="multipart/form-data">
<span class="btn btn-success btn-block btnrec btn-file">
Upload <input type="file" name="file">
</span>
<input class="btn btn-success btn-block btnrec" type="submit" name="submit">
</form>
<!-- don't care about IE8 -->
<form action="" method="post" enctype="multipart/form-data">
<label class="btn btn-success btn-block btnrec btn-file">
Upload <input style="display: none;" type="file" name="file">
</label>
<input class="btn btn-success btn-block btnrec" type="submit" name="submit">
</form>
<style>
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
</style>

Related

Hide nested button based on an inputs value

I have a form with a button inside it which I need to hide.
<form method="get">
<input type="hidden" name="id" value="7245">
<input type="hidden" name="action" value="removesubmissionconfirm">
<button type="submit" class="btn btn-secondary" title="">Remove submission</button>
</form>
There are multiple forms with the exact same values as the above, the only difference being the value="removesubmissionconfirm". Is it possible to hide the button based on that value using only css?
I've tried a lot of things and nothing seems to work.
TIA.
You can do it using the attribute selector and the + selector :
input[value="removesubmissionconfirm"] + button {
display: none;
}
<form method="get">
<input type="hidden" name="id" value="7245">
<input type="hidden" name="action" value="removesubmissionconfirm">
<button type="submit" class="btn btn-secondary" title="">Remove submission</button>
</form>
Generally no, but it may be in this specific example, considering the fact that the button comes directly after the hidden action field. Try this:
input[value="removesubmissionconfirm"] + button {
display: none;
}
input[value="removesubmissionconfirm"] + button {
display: none;
}
<form method="get">
<input type="hidden" name="id" value="7245">
<input type="hidden" name="action" value="removesubmissionconfirm">
<button type="submit" class="btn btn-secondary" title="">Remove submission</button>
</form>

How to hide input file type but still display the file uploaded?

I have a code that has an input file type that is hidden but called on from the paperclip icon, however it doesnt show the user that a file has been chosen for upload.
If i remove display none from the input field you will see "Choose a file" along with the file I chose. is there a way just to show the file once it has been uploaded, for example:
Here is the code I have so far:
<div class="chat-right">
<input type="file" name="file" class="form-control" style="display:none;" id="hidden_upload_file_chatting">
<img src="<?php echo base_url();?>/assest/icon-img/paperclip.png" class="ic_img" onclick="$('input#hidden_upload_file_chatting').click();">
<button type="submit" class="btn btn-flat" name="reply" value="reply" >Reply</button>
<button type="button" class="btn btn-flat" data-dismiss="modal" style="margin-left: 10px !important;">Close</button>
</div>
I just write a basic code snippet for file open on a icon click. Try this I hope it'll help you out. Thanks
.chat-right {
display: flex;
}
.fileUploadWrap {
background-image: url('https://cdn2.iconfinder.com/data/icons/budicon-document-2/16/69-document_-_attachment_clip_paperclip-512.png');
background-repeat: no-repeat;
background-size: contain;
position: relative;
height: 40px;
width: 40px;
}
#hidden_upload_file_chatting {
opacity: 0;
position: absolute;
height: 100%;
width: 100%;
}
<div class="chat-right">
<div class="fileUploadWrap">
<input type="file" name="file" class="form-control" id="hidden_upload_file_chatting">
</div>
<button type="submit" class="btn btn-flat" name="reply" value="reply" >Reply</button>
<button type="button" class="btn btn-flat" data-dismiss="modal" style="margin-left: 10px !important;">Close</button>
</div>
var fileBtn = document.getElementById('fileUpload');
var sName = document.getElementById('_showName');
fileBtn.addEventListener('change', function(_th){
if(this.files.length)
sName.innerText = this.files[0].name;
else
sName.innerText = '';
});
<div class="chat-right">
<label>
<img src="<?php echo base_url();?>/assest/icon-img/paperclip.png" class="ic_img" >
<span id="_showName"></span>
<input type="file" name="file" class="form-control" style="display:none;" id="fileUpload">
</label>
<button type="submit" class="btn btn-flat" name="reply" value="reply" >Reply</button>
<button type="button" class="btn btn-flat" data-dismiss="modal" style="margin-left: 10px !important;">Close</button>
</div>

bootstrap align button to form submit button in td

I'm using bootstrap on my Symfony app and in my index action, I display a table with all items and two buttons to update or delete an item. In fact I'm not using to buttons I use one button to modify the entity and a form with hidden inputs and the submit button to delete this item.
Currently the submit button is displayed below the update button and what I want is to display the two buttons aligned.
Thanks by advance if you have the solution of my problem
here is my code:
<td>
Modifier
<form action="/app_dev.php/quotes/2/delete">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-sm btn-danger">Supprimer</button>
</form>
</td>
first thing I don't understand that why you are using a form. you can easily call the desired URL with a parameter on an onClick event.
But still if it is necessary then you can add a property to form and it's element to be style="display:inline-block;" or can write a separate css.
form {
display:inline-block;
}
this will be helpful
<style>
.div1, .div2{
display: inline-block;
}
</style>
<body>
<td>
<div class="div1">Modifier</div>
<div class="div2"><form action="/app_dev.php/quotes/2/delete">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-sm btn-danger">Supprimer</button>
</form></div>
</td>
</body>
HTML
<td class="button-container">
Modifier
<form action="/app_dev.php/quotes/2/delete">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-sm btn-danger">Supprimer</button>
</form>
</td>
CSS
.button-container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 10px;
}
Additionally, you can make button 100%
.button-container .btn {
width: 100%;
}
You can accomplish that by many ways. One simple form would be to add float: left to the link, like this:
<td>
Modifier
<form action="/app_dev.php/quotes/2/delete" >
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-sm btn-danger">Supprimer</button>
</form>
</td>
<td class="flex">
Modifier
<form action="/app_dev.php/quotes/2/delete">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-sm btn-danger">Supprimer</button>
</form>
</td>
in your css :
.flex {
display: flex;
}
good source for display with flex https://openclassrooms.com/courses/apprenez-a-creer-votre-site-web-avec-html5-et-css3/la-mise-en-page-avec-flexbox (in french)
Ok thank you all for your answers, I find out to align those two buttons by using bootstrap flex classes, here the entiere solution:
<td class="d-flex flex-row">
{{ 'wallofquotes.ui.update'|trans }}
<form method="POST" action="{{ path('wallofquotes_quote_delete', {'id': quote.id}) }}">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-sm btn-danger">{{ 'wallofquotes.ui.delete'|trans }}</button>
</form>
</td>

Label doesn't work

I have this code:
.hidden_element {
height: 1px;
width: 1px;
overflow: hidden;
}
<form action="">
<label for="file">
<button type="button" class="button red">Choose File</button>
</label>
<div class="hidden_element">
<input type="file" name="video" id="file" />
</div>
</form>
The problem is when I click choose file nothing happens.
Change your button like <button type="button" onclick="document.getElementById('file').click()" class="button red">Choose File</button>
.hidden_element {
height: 1px;
width: 1px;
overflow: hidden;
}
<form action="">
<label for="file">
<button type="button" onclick="document.getElementById('file').click()" class="button red">Choose File</button>
</label>
<div class="hidden_element">
<input type="file" name="video" id="file" />
</div>
</form>
The label element applies to one input only: since it has one as a child (the button is an input element), it applies to it instead of the file-input as you hoped.
Just remove the button, maybe replace it with a span and style it as you wish, and clicking the label will open the file picker. No javascript needed! :)
.hidden_element {
height: 1px;
width: 1px;
overflow: hidden;
}
.button {
display: inline-block;
box-sizing: border-box;
border: 1px solid #aaa;
background-image: linear-gradient(to bottom, #eee, #ccc);
padding: 0.1em 0.2em;
cursor: pointer;
}
<form action="">
<label for="file">
<span class="button red">Choose File</span>
</label>
<div class="hidden_element">
<input type="file" name="video" id="file" />
</div>
</form>
I do not see the purpose of putting the button as a label. Either use a button or a submit to process your input (file upload). You should not hide your 'input file' tag. You really need two things for the user: the 'input file' tag to allow the user to choose the file he wants to upload and then a way to perform an action by submitting the form or perhaps an ajax call. However, since you are just learning this process, I recommend, just performing a simple submit and for you to write the code on the backend that will handle uploading the file. Here is a sample of my html code:
<form method="post" action="uploadFile.php">
<input type="file" name="video" id="file" />
<br /><br />
<input type="submit" value="upload file">
</form>

HTML button loop

Hello guys i'm trying to figure out how can I add more textboxes by clicking an add button.
I'm using codeigniter framework so here is my view:
<form action="save_new_inventorytype" method="POST">
<fieldset>
<legend>Add New Inventory Type</legend>
<label id="lbl_tablename" name="lbl_tablename">Inventory Type Name:</label>
<input type="text" id="txt_tablename" name="txt_tablename" size="30" /><br>
<label id="lbl_columns" name="lbl_columns" style="position: absolute; top: 276px;">Column Name:</label>
<label style="position: absolute; top: 276px; left: 352px;">Type:</label>
<label style="position: absolute; top: 276px; left: 565px;">Length/Values:</label><br>
<br>
<input type="text" id="txt_columnname" name="txt_columnname" size="30"/>
<select id="cbo_columntype" name="cbo_columntype" style="width: 200px;">
<option>INT</option>
<option>VARCHAR</option>
<option>TEXT</option>
<option>DATE</option>
</select>
<input type="text" id="txt_columnlength" name="txt_columnlength" size="30"/>
<button type="button" class="btn_plusvalue btn-success btn-sm"><span class="glyphicon glyphicon-plus"></span></button><br>
<br>
<button type="button" class="btn_addtable btn-success btn-sm" id="btn_addtable" name="btn_addtable">Save Inventory Type</button>
<button type="button" class="btn_canceltable btn-danger btn-sm">Cancel</button>
<button type="button" class="btn_cleartable btn-warning btn-sm">Clear</button>
</fieldset>
</form>
Here is a print screen of my view:
I want to have those three(textbox,combobox,textbox) to duplicate when I click on that plus button.
Can anyone help me on this one? Please? I know that I have to use loop but I don't know how.
I have jquery solution for adding textbox on click of button. try something like this:
Suppose, you have form and button like:
<form>
<input type="button" value="Add textbox" name="add" id="add"/>
</form>
then use append method in script tags:
var r;
$(function(){
$('#add').on('click',function(){
for(var i=0;i<10;i++){
r= $('<input type="text" value="textbox" id="i"/>');
}
$("form").append(r);
});
});
here, <input type="text" value="textbox"/> is taken as variable and then appended to the form.
DEMO FIDDLE HERE.
Hi, Here is exactly that you wanted.