Nothing happens when submit button is pressed - html

I do not know what I've done wrong, this works perfectly on the index page with of course another code, something smaller, but the form submits there.
Here I am trying to make a modal with a form, the form will be used to create a new article but the submit button isn't working, nothing is happening when it gets pressed. I really don't know whats wrong with it.
Code:
<div class="modal fade" id="createArticle" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Create a new article</h4>
<small style="color:orange">Please add only important articles to the quick links</small>
</div>
<div class="modal-body">
<form onsubmit="return validate();" action="" method="post">
<div class="form-group">
<label for="createArticleTitle">Title:</label>
<input type="input" class="form-control" id="createArticleTitle" name="createArticleTitle" maxlength="250" placeholder="Insert Article Title...">
</div>
<!-- /.box -->
<div class="box">
<div class="box-header">
<h3 class="box-title">Article Message:<br>
<small><u>Text Formatting</u><br><br>
Use <code>[center] Your text here [/center]</code> to center your message.<br>
Use <code>[b] Your text here [/b]</code> to make your message <strong>bold</strong>.<br>
Use <code>[i] Your text here [/i]</code> to to make your message <i>italic</i>.<br>
Use <code>[u] Your text here [/u]</code> to underline your message.<br>
Use <code>[img] img url here [/img]</code> to insert a image.<br>
Use <code>[rigt/left] Your text here [/right/left]</code> to align your message on the right or on the left.<br>
Use <code>[ul] Your text here [/ul]</code> for a unordered list, use <code>[*]</code> to add items.<br>
Example: <code>[ul][*] Apple[/ul]</code> - dotes<br>
Example: <code>[ol][*] Apple[/ol]</code> - numbers<br><br>
Use <code>[quote] Your text here [/quote]</code> to add a quote.<br>
Use <code>[url=link] Your url title here [/url]</code> to insert a url.<br>
Use <code>[code] Your code here [/code]</code> to insert code.</small>
</h3>
<!-- tools box -->
<div class="pull-right box-tools">
<button type="button" class="btn btn-default btn-sm" data-widget="collapse" data-toggle="tooltip" title="Collapse">
<i class="fa fa-minus"></i></button>
</div>
<!-- /. tools -->
</div>
<!-- /.box-header -->
<div class="box-body pad">
<form>
<textarea class="textarea" placeholder="Insert the article here..." id="createArticleMes" name="createArticleMes" maxlength="10000" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
</form>
</div>
<br>
<div class="custom-controls-stacked">
<label for="createArticleQuick">Do you want to show this article to the Quick Links in the footer?</label>
<br>
<label class="custom-control custom-radio">
<input id="createArticleQuick" name="createArticleQuick" type="radio" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Yes</span>
</label>
</div>
</div>
<button type="submit" name="createArticleButton" class="btn btn-default">Create</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Here is the function too:
<script>
function validate(){
var n1 = document.getElementById("createArticleTitle");
var n2 = document.getElementById("createArticleMes");
if(n1.value != "" && n2.value != ""){
return true;
}
alert("You must add a title and a message atleast.");
return false;
}
</script>

Instead of using <form> tag without any attributes try using something like this
<form action="welcome.php" method="post">

The issue was that I was using twice
<div class="box-body pad">
<form>
<textarea class="textarea" placeholder="Insert the article here..." id="createArticleMes" name="createArticleMes" maxlength="10000" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
</form>
</div>

Related

Form doesn't work when submit button is in the modal window

I have HTML form with submit button inside. Inside the form there are piece of HTML code which popups in modal window when filling up the form. Inside this modal are one more input and submit button. And it does not work, the form doesn't send to email. But when I move entire button HTML code right before </form> then submit button works. Here is a code:
<form name="autoForm" id="contact-form" class="row" method="post" action="php/send.php">
<div class="form-group col-md-6">
<label id="address-label" for="place">* Markė | modelis | metai | TA | miestas</label>
<input id="form_place" type="text" name="place" class="form-control" data-error="Laukas privalomas" >
<div class="help-block with-errors"></div>
</div>
<div class="form-group col-md-12">
<label for="message">Automobilio būklė</label>
<textarea id="form_message" name="message" class="form-control h-auto" rows="4" data-error="Prašau, parašykite daugiau apie NT"
placeholder="Čia galite parašyti daugiau informacijos apie automobilio būklę"></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="submit-container col mt-5">
<a class="btn btn-primary" id="to-modal-form"><font size="4">Sužinoti kainą</font></a>
</div>
<div id="modal-background" class="modal-background container-hidden">
<div id="modal-form" class="modal-form">
<a id="modal-close"><i class="icon-close" data-v-27b8b94e=""></i></a>
<div class="form-header">
<h2>Gaukite kainos pasiūlymus tiesiai į savo telefoną.</h2>
<p>Įveskite telefono numerį ir gaukite pasiūlymo nuorodą <b>SMS</b></p>
</div>
<div class="form-body">
<div class="form-group col-md-6">
<label class="phone" for="phone">* Jūsų telefono numeris</label>
<input id="form_phone" type="phone" name="phone" class="form-control" required="required" data-error="Laukas privalomas">
<div class="help-block with-errors"></div>
</div>
<input type="hidden" name="code" value="" id="code" />
<button class="btn btn-primary" type="submit" id="form_submit"><font size="4">Tęsti</font></button>
<span class="privacy">Sutinku su privatumo politika</span>
</div>
</div>
</form>
Filling up first inputs there are first button <a class="btn btn-primary" id="to-modal-form"><font size="4">Sužinoti kainą</font></a> which is opening the modal windows. Inside after filling up additional input I press <button class="btn btn-primary" type="submit" id="form_submit"><font size="4">Tęsti</font></button> which doesn't work.
But form work when button is moved before </form>. Form sends all values - inside and out of modal window.
Can't get what is wrong.
If you have button outside </form> it would not work the solution is using form="" parameter to the button it basically tell this button belong to this specific form element
<button class="btn btn-primary" form="contact-form" type="submit" id="form_submit"><font size="4">Tęsti</font></button>
Your submit button will confused which form that it should submitted if you place it outside the form tag.
You could use javascript to submit the form.
https://www.javascript-coder.com/javascript-form/javascript-form-submit/
Put a button inside your modal with onclick="submitForm('contact-form');", then add below js code
function submitForm(id) {
document.getElementById(id).submit();
}
Solved this by adding submit button before with attribute hidden:
<form>
<!-- the form content -->
<button class="btn btn-primary" type="submit" id="form_submit" hidden></button>
</form>
And that button inside of modal window made as trigger with attribute onclick="submitForm();" like this:
<button class="btn btn-primary" onclick="submitForm();"><font size="4">Tęsti</font></button>
In JS it triggers submit button using .click() method:
const submitBtn = document.getElementById('form_submit');
function submitForm() {
submitBtn.click();
}

safe input from form in modalbox

I am making a signup form for our e-mail newsletter with Bootstrap 3. I made a row where it is possible to type in a name and e-mail. When a person click "Compete Now" there is coming a modalbox up where the person has to give 3 informations.
The question is now if it is possible to save the information from earlier? That means the name and e-mail?
So the data I have to send to MailChimp is:
Name
E-mail
Workshop
Gender
Postcode
As it is now I can send the data "Workshop, Gender and Postcode" to MailChimp. But the modalbox is of course not remembering the name and e-mail.
Is there a way that I can save the name and e-mail? One important thing is that I do not have access to the backend. That means if it was possible it had to be done with javascript.
There is a working JSFiddle here
Notice it is not possible to convert to BS4 at the moment
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').focus()
})
.newsletter-block {
background-color: #7c7c7c;
}
.newsletter-title h2 {
padding-bottom: 24px;
font-size: 2em;
}
.newsletter-subtitle {
font-size: 16px;
}
.padd-70-70 {
padding-top: 70px;
padding-bottom: 70px;
}
.subscribe-form {
width: 100%;
}
.subscribe-form .form-control {
border-radius: 0px;
}
.subscribe-form button {
border: 2px solid #e4a228;
background: #e4a228;
text-transform: uppercase;
color: #fff;
text-align: center;
width: 100%;
padding: 0.4em;
}
<div class="main-wraper padd-70-70 newsletter-block">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12 col-xs-12 d-flex justify-content-end">
<div class="newsletter-title">
<h2 class="color-white">Join Suite Vacations to Get FREE <br>Travel News and Special Offers!</h2>
<h4 class="newsletter-subtitle color-white underline">Secret Deals - for our subscribers only...Besides it's FREE</h4>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 d-md-flex justify-content-start ">
<form class="subscribe-form" action="#">
<div class="form-group subscribe-input input-style-1 fl low-pad">
<input type="text" class="form-control" required="true" placeholder="Navn">
</div>
<div class="form-group subscribe-input input-style-1 fl low-pad">
<input type="email" class="form-control" required="true" placeholder="Din e-mail">
</div>
<button type="submit" class="c-button b-60 bg-red-3 hv-red-3-o fr btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"><span>Compete Now</span></button>
</form>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="mc-field-group">
<label for="mce-VAERKSTED">Workshop <span class="asterisk">*</span>
</label>
<input type="text" value="" name="VAERKSTED" class="required" id="mce-VAERKSTED">
</div>
<div class="mc-field-group input-group">
<strong>Gender <span class="asterisk">*</span>
</strong>
<ul><li><input type="radio" value="Mand" name="KON" id="mce-KON-0"><label for="mce-KON-0">Man</label></li>
<li><input type="radio" value="Kvinde" name="KON" id="mce-KON-1"><label for="mce-KON-1">Woman</label></li>
</ul>
</div>
<div class="mc-field-group size1of2">
<label for="mce-ZIP">Postcode <span class="asterisk">*</span>
</label>
<input type="number" name="ZIP" class="required" value="" id="mce-ZIP">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Subscribe</button>
</div>
</div>
</div>
</div>
You do not need to save the "data for later" as both the popup and the initial form are on the same page. After the popup window occurs and the user clicks "Subscribe" you can simply collect the data from the name and e-mail input boxes and pass this data along to the backend.
1.) Add ID values to the name and e-mail fields:
<div class="form-group subscribe-input input-style-1 fl low-pad">
<input type="text" id="navn" class="form-control" required="true" placeholder="Navn">
</div>
<div class="form-group subscribe-input input-style-1 fl low-pad">
<input type="email" id="email" class="form-control" required="true" placeholder="Din e-mail">
</div>
(Also remove the action from your <form> tag otherwise the form will be submitted when clicking on the "COMP(L)ETE NOW" button: <form class="subscribe-form">).
2.) Add an ID to the "Subscribe" button in the popup form so you can attach a handler to it:
<button type="button" id="btn-subscribe" class="btn btn-primary">Subscribe</button>
3.) Create an event handler to handle the signup process:
$('#btn-subscribe').on('click', function() {
let navn = $('#navn').val();
let email = $('#email').val();
let workshop = $('#mce-VAERKSTED').val();
let gender = $('#mce-KON-1').is(':checked') ? 'Kvinde' : 'Mand';
let zip = $('#mce-ZIP').val();
window.alert(navn + ' - ' + email + ' - ' + workshop + ' - ' + gender + ' - ' + zip);
});
Here is a Fiddle to demonstrate the change.
Update code
In case you need a form wrapper for MailChimp:
move the <form> tag to the popup window.
Add two hidden form fields to the form to hold the values for the name and e-mail
On showing the modal, copy the name and e-mail values into the hidden fields
In my tests I could not wrap the entire modal in a <FORM> tag as this would change the entire layout of the popup. What I ended up doing was to add the <FORM> in the <div class="modal-body>...</div> and then submit the form via an event handler on the subscribe button:
$('#btn-subscribe').on('click', function() {
$('#subscribe-form').submit();
});
Some final remarks:
your fiddle contains a <style> tag in the CSS window which causes a display issue in the fiddle
get rid of old tags like <strong> and use CSS classes instead. If you ever want to change the styling of your code, you simply need to change the CSS rather than having to change tags.
Here is an updated Fiddle.

Bootstrap form not rendering without additional form element

I'm having a problem with a form inside of a modal using Bootstrap 3.2.2. Here's my HTML:
<div class="modal fade" id="emailModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true" class="fa fa-close"></span><span class="sr-only">Close</span></button>
<h4 class="modal-title"><span style="padding-right:10px;" class="fa fa-envelope" aria-hidden="true"></span>E-Mail Developer</h4>
</div> <!-- .modal-header -->
<div class="modal-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="toEmailInput" class="col-sm-2 control-label">To</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="toEmailInput" placeholder="Enter Email" />
</div>
</div>
<div class="form-group">
<label for="subjectInput" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="subjectInput" placeholder="Enter Subject" />
</div>
</div>
<div class="form-group">
<label for="messageInput" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="no-resize form-control" id="messageInput" rows="5" placeholder="Enter Message"></textarea>
</div>
</div>
</form>
</div> <!-- .modal-body -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Send</button>
</div> <!-- .modal-footer -->
</div> <!-- .modal-content -->
</div> <!-- .modal-dialog -->
</div> <!-- .modal -->
This renders this:
But, if I add an additional tag <form role="form"></form> anywhere in the page, I get this:
Any idea of what witchcraft is going on behind the scenes here? I would expect it to look like the second picture without additional form tags.
UPDATE - After taking a look at the applied CSS from my before & after, it looks like the removal of the additional <form> tag also removes the applied .form-horizontal styling from the form itself. I'm continuing to investigate, but I have a feeling it has to do with something about the way the site is configured.
UPDATE - I found the issue. Without the additional <form> tag, there's some funkiness in the web app that is removing the surrounding <form class="form-horizontal"> tag but leaving the form-groups alone. Very strange!
UPDATE - Well, surprise surprise. Turns out my ASP.NET Web Forms (yes, with a <form runat="server"> tag) strips out "nested" form elements. Yes, I realize I didn't mention I was using web forms, but I was hoping it was unrelated. Turns out it's completely related!
Turns out this is due to ASP.NET Web Form's innate ability to strip out nested <form> tags from its "master" <form runat="server"> form used for post-backs.
To prove this, I changed my <form class="form-horizontal"> into a simple <div> with the same class, and it worked fine.
I was able to recreate your problem in JSFiddle. So probably you should check your paddings and one margin of the following classes. I think you are overriding them by your CSS, so you should check it.
.modal-body {
position: relative;
padding: 15px;
/*modified by me to reproduce your problem, check out where you are setting
the bottom padding to 0 (should be 15px)*/
padding-bottom: 0;
}
.form-group {
/*modified by me to reproduce your problem, check out where you are setting
the bottom margin to 0 (should be 15px)*/
margin-bottom: 0px;
}
.modal-footer {
padding: 15px;
text-align: right;
border-top: 1px solid #e5e5e5;
/*modified by me to reproduce your problem, check out where you are setting
the bottom & right padding to 0 (should be 15px)*/
padding-top: 0;
padding-right: 0;
}
Here is my fiddle using your code:
JSFIDDLE
I added a button for ease of use. Because i'm not referencing the stylesheet that has the ".control-label" and ".no-resize" classes, I'm not getting the same problem.
I really think that your issue lies in one of those two aforementioned classes that are not BootStrap classes.
Can you share the rules for those two classes?
Thanks!
.control-label {?}
.no-resize {?}

search icon with form element inside input box

I am trying to add search image inside search box with form element.
My code is
<div class="col-xs-9">
<form action="search">
<input class="form-control" type="search" />
<span class="glyphicon glyphicon-search"></span>
<button type="submit" class="btn"><i class="glyphicon glyphicon-search"></i>
</button>
</form>
</div>
I want when user click on the search image inside search box form action should call
code is http://jsfiddle.net/chetfarley/WK3Q6/1/
Trying code from https://stackoverflow.com/a/19918345/876739
You can do it like this:
HTML:
<div class="col-xs-9">
<input class="form-control" type="search" />
<button type="submit"><span class="glyphicon glyphicon-search"></span></button>
</div>
CSS:
.form-control + button {
position: absolute;
right: 20px;
top: 7px;
border: 0;
background-color: transparent;
box-shadow: none;
}
And a little event listener, you won't need if you just want the form to be submited:
document.getElementsByTagName("button")[0].addEventListener("click", function(){
alert("doing");
});
Here is the demo: http://jsfiddle.net/WK3Q6/275/

Dropdown with a form inside with twitter-bootstrap

I have a Dropdown in my TopBar, built with the Twitter Bootstrap CSS framework.
I have 3 problems with it that I can't find any solution to:
The text and password input fields are far too big, how can I adjust them? Making the dropdown box bigger would be OK too.
The labels for the fields are too dark, how can I lighten them up a bit?
The Dropdown is closing when I click into one of the fields. I have to reopen it and then I can type until clicking in the next field. The values are preserved even when the dropdown is closed. How can I make it stay open?
Here is a screenshot of problems 1 and 2:
Also here is the HTML for the TopBar as it is now.
<div class='topbar-wrapper'>
<div class='topbar'>
<div class='topbar-inner'>
<div class='container'>
<h3>
Webworld
</h3>
<ul class='nav'>
<li>FILLER...</li>
</ul>
<ul class='nav secondary-nav'>
<li class='dropdown' data-dropdown='dropdown'>
Login
<div class='dropdown-menu' id='signin-dropdown'>
<form accept-charset="UTF-8" action="/sessions" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="4L/A2ZMYkhTD3IiNDMTuB/fhPRvyCNGEsaZocUUpw40=" /></div>
<fieldset class='textbox'>
<label id='js-username'>
<span>Username</span>
<input autocomplete="on" id="username" name="username" type="text" />
</label>
<label id='password'>
<span>Passwort</span>
<input id="userpassword" name="userpassword" type="password" />
</label>
</fieldset>
<fieldset class='subchk'>
<input name="commit" type="submit" value="Log In" />
</fieldset>
</form>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
There hidden input is needed by rails and autogenerated.
I've already tried to copy the implementation of the login form that twitter uses, but when I tried that, the TopBar is about 250px in height and the content of the dropdown is open, not closeable.
I have no custom CSS or JavaScript so far, except for the top-padding of 40px in the body as suggested by the bootstrap docs.
Can someone help me with this?
Try adding the code below somewhere in your javascript. It should stop it from happening.
$('.dropdown-menu').find('form').click(function (e) {
e.stopPropagation();
});
(Twitter Bootstrap 2.x)
You may want to move the contents of style="" to your stylesheets...
If user entered wrong password:
add class open to li class="dropdown open"
and class error to fieldset class="control-group error"
<ul class="nav pull-right">
<li class="dropdown">
Login <b class="caret"></b>
<div class="dropdown-menu">
<form action="" id="form_login" style="margin: 0; padding: 3px 15px" accept-charset="utf-8" method="post">
<fieldset class="control-group">
<label for="form_email" class="control-label">Email address</label>
<div class="controls">
<div class="input-prepend" style="white-space: nowrap">
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="email" name="email" id="form_email" autocomplete="on" class="span2">
</div>
</div>
</fieldset>
<fieldset class="control-group">
<label for="form_password" class="control-label">Password</label>
<div class="controls">
<div class="input-prepend" style="white-space: nowrap">
<span class="add-on"><i class="icon-lock"></i></span>
<input type="password" name="password" id="form_password" class="span2">
</div>
</div>
</fieldset>
<label class="checkbox">
<input type="checkbox" name="remember" value="true"> Remember me
</label>
<p class="navbar-text">
<button type="submit" class="btn btn-primary">Login</button>
</p>
</form>
</div>
</li>
</ul>
You don't need any extra css or javascript to make this look nice (with TB2.x)
In case you don't want to stop propagation of your events, or that solution didn't work for you, you can add this code somewhere near initialization of bootstrap-dropdown:
$('html').off('click.dropdown.data-api');
$('html').on('click.dropdown.data-api', function(e) {
if(!$(e.target).parents().is('.dropdown-menu form')) {
$('.dropdown').removeClass('open');
}
});
For your third question - In your bootstrap-dropdown.js comment source code row
$('html').on('click.dropdown.data-api', clearMenus)
and write there this:
$(document).bind('click', function(e) {
var $clicked = $(e.target);
if (!$clicked.hasClass("dropdown-menu") &&
!$clicked.parents().hasClass("dropdown-menu")){
clearMenus();
}
});
https://github.com/twitter/bootstrap/blob/master/bootstrap.css#L1559
max-width is set to 220px, remove the attribute and it will stretch itself.
Its looks like a CSS based problem u are facing.
I fixed it with the following styles:
#signin-dropdown {
padding-left: 5px;
padding-right: 5px;
padding-top: 1em;
}
#signin-dropdown form {
margin:0px;
}
#signin-dropdown form .textbox {
margin-bottom:0em;
padding-top:0em;
}
#signin-dropdown form .subchk {
margin-bottom: 5px;
padding-top: 8px;
}
#username, #password, #userpassword {
color: #404040;
float: left;
font-size: 13px;
line-height: 18px;
padding-top: 0px;
text-align: left !important;
width: 140px;
}
About your questions 1 and 2.
Have you tried setting the length of the input? You can do this by setting the "size" attribute of the input tag. You can read more here
Did you try changing the style of the label? For example:
<span style="color:#FFFFFF">Username </span>
you just add your content in <form></form> tag
like this:
<div class="dropdown dropdown-scroll" id="selectedClient">
<button class="btn btn-block btn-lg btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
انتخاب <span class="caret"></span>
</button>
<div class="dropdown-menu " role="menu" aria-labelledby="dropdownMenu1">
<button type="button" class="close">×</button>
<form>
<ul>
<li role="presentation">
<input id="searchSubClientInput" type="text" class="form-control" placeholder="جستجو بر اساس نام خانوادگی" ng-model="query">
</li>
</ul>
</form>
<ul class="select-list scrollable-menu">
<li class="dropdown-header">خودم</li>
</ul>
</div>
</div>