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.
Related
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();
}
Have a form where user enters answers to questions. I want all user entered data to appear in a popup along with the corresponding question. If the user decides not to answer a question I do not want the question or anything associated with that question to appear. I was told this could be done by converting entered data to a json object. I am not sure how to do this or if there is a better way. I want to be able to do it all withing the same component.
I tried doing this How do I create popup with data user enters into a form? but could not figure it out. I also want to be able to achieve this without creating more components.
//This is the .html file
<div ng-app="DemoApp" ng-controller="DemoController" class="form-row align-items-center">
<div class="col-auto">
<br />
<div class="form-group">
<label for="controlSelect1" >Select your tower...</label>
<select class="form-control" name="exampleFormControlSelect1" formControlName="controlSelect1">
<option></option>
<option>Clown</option>
<option>Clampionship</option>
<option>Other</option>
</select>
</div>
<div class="form-group">
<label for="caseNumber">Case Number(s): </label>
<textarea class="form-control" name="caseNumber" formControlName="caseNumber" rows="1" placeholder="Separate case numbers by comma"></textarea>
</div>
<div class="form-group">
<label for="visitPurpose">Purpose of Lab Visit: </label>
<textarea class="form-control" name="visitPurpose" formControlName="visitPurpose" rows="1"></textarea>
</div>
<label for="needRescources">Need any Lab Rescource(s)?</label>
<br />
<div class="form-check form-check-inline" name="labRescource" formControlName="labRescource">
<input type="checkbox" class="form-check-input" formControlName="labAdmin">
<label class="form-check-label" for="Lab Admin">Lab Admin </label>
<input type="checkbox" class="form-check-input" formControlName="toolCart">
<label class="form-check-label" for="Tool Cart">Tool Cart </label>
<input type="checkbox" class="form-check-input" formControlName="other">
<label class="form-check-label" for="Other">Other</label>
</div>
<br /><br />
<div class="form-group">
<label for="additionalNotes">Any additional notes? </label>
<textarea class="form-control" name="additionalNotes" formControlName="additionalNotes" rows="1"></textarea>
</div>
</div>
</div>
<p>
Form Value: {{ labForm.value | json }}
</p>
<p>
Form Status: {{ labForm.status }}
</p>
<button type="submit" class="btn btn-default" [disabled]="!labForm.valid">Build Lab Request</button>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Template</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title text-left">Lab Access Template</h4>
</div>
<div class="modal-body">
<label for="exampleFormControlSelect1">Requester's Tower:</label>
<br /><label for="caseNumber">Case Number(s): </label>
<br /><label for="visitPurpose">Purpose of Lab Visit: </label>
<br /><label for="needRescources">Need any Lab Rescource(s)?</label>
{{ labForm.value | json }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Copy Template</button>
</div>
</div>
</div>
</div>
//This is the .ts file
import { Component } from '#angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from'#angular/forms';
#Component({
selector: 'app-lab-access',
templateUrl: './lab-access.component.html',
styleUrls: ['./lab-access.component.scss']
})
/** LabAccess component*/
export class LabAccessComponent {
labForm = new FormGroup({
ControlSelect1: new FormControl(''),
caseNumber: new FormControl('', Validators.required),
visitPurpose: new FormControl('', Validators.required),
/**lab rescource check boxes*/
labAdmin: new FormControl(''),
toolCart: new FormControl(''),
other: new FormControl(''),
});
onSubmit() {
console.warn(this.labForm.value);
}
labAccessForm: FormGroup;
/** LabAccess ctor */
constructor() { }
}
The form data is not appearing on popup in the format I desire. Would like it to look like below.
Requestor's Tower: Clown
Case Number: 328792892
Purpose of Visit: Felt like dropping by.
Needed Resources: Tool Cart
If user did not fill out one of the questions I do not want question appear.
This is how I decided to answer the question.
I have a modal popup and the output is generated using this code.
<div *ngIf="form.value.Num1">Part Number(s): {{form.value.Num1}}</div>
I have some fields inside a form tag and submit button outside a form tag. If any of the fields inside a form is empty my form should not be submitted. For this I used the required attribute but it was not working since submit button was outside of the <form> and also used novalidate attribute. Nothing seems to work.
Below is my code:
<section id="profile" class="content-header">
<div class="thumbnail">
<button type="submit" class="btn btn-block btn-success" ng-if="!viewProfile" ng-click="updateProfile();">SUBMIT</button>
</div>
<div class="row">
<form name="profileForm" role="form">
<div class="form-group col-md-6">
<label for="firstName"> First Name </label>
<input type="text" class="form-control" id="firstName" ng- model="profileDetails.firstName" ng-disabled="viewProfile" required/>
</div>
<div class="form-group col-md-6" ng-if="userDetails.role==0">
<label for="firstName"> Middle Name </label>
<input type="text" class="form-control" id="middleName" ng- model="profileDetails.middleName" ng-disabled="viewProfile" />
</div>
</form>
</div>
</section>
like FirstName and MiddleName there are many other fields without filling any of those fields my form should not be submitted, can anyone suggest me the best approach for this. My angularController is:
(function() {
function profileController($scope, profileFactory, $loading) {
$scope.updateProfile = function() {
$loading.start("main");
profileFactory
.updateProfile($scope.profileDetails)
.then(function(response) {
var updatedUserDetails = response.user;
if (updatedUserDetails.imagePath !== null) {
$scope.profileDetails.imagePath = updatedUserDetails.imagePath;
$scope.profileDetails.profieImageBytes = updatedUserDetails.profieImageBytes;
}
angular.extend($scope.userDetails, $scope.profileDetails);
$scope.editProfile();
})
.catch(function() {
$loading.finish("main");
});
};
$loading.finish("main");
}
profileController.$inject = ["$scope", "profileFactory", "$loading"];
angular
.module("vResume.profile")
.controller("profileController", profileController);
})();
You typically use the .$invalid field on the form with ng-disabled for this.
<button type="submit" class="btn btn-block btn-success" ng-disabled="profileForm.$invalid" ng-if="!viewProfile" ng-click="updateProfile();">SUBMIT</button>
See the angularjs docs.
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>
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 {?}