Error in my JQuery validation - php

Hello i have error in my Jquery validation, the code dont do nothing, can anybody help me?
<script>
// When the user submits the form,
// Check what answer they picked
// And tell them if they're correct
// submit
$("#form").on("submit", function(event) {
event.preventDefault();
var $answer = $("#unit_name");
var answer = $answer.val();
console.log(answer);
if (answer === "") {
$("#result").text("Preencha corretamente o nome da unidade.");
} else if(answer.length < 3 ) {
$("#result").text("O nome da unidade é demasiado pequeno.");
}
});
</script>
This is the code of the form implemented
<div class="pure-u-1">
<h3 align="center">Insert</h3>
</div>
<div class="form-group">
<label class="control-label" for="unit_name"Name concept:</label>
<div class="input-group">
<input class="form-control" placeholder="Insert name" id="unit_name" name="unit_name" type="text" />
</div>
</div>
<input type="hidden" name="state" value="insert">
<input type="submit" value="Insert">
<br><br>
</div>
</form>
This div will show message to the users.

First think I noticed is that the label tag doesn't have a closing ">". It isn't in the HTML code, but does the form tag have an id of "form"?
The two lines var $answer... and var answer... could be combined to
var answer = $('#unit_name').val();
Lastly, in your html code, do you have a div (or other tag) with an id="result"? If so, is it hidden? If it is hidden, after setting your message, you will need to un-hide it.

Related

Submit Form Data to Google Spreadsheet in another tab (sheet)

I have a website here having two Forms. One under RESERVE VIP TABLE and another in the footer where it says JOIN OUR NEWSLETTER. I've used the following code to submit data from the FORM to Google Sheets. Question is that the first form is working fine but how can I submit the data from Newsletter section to Google Sheets in a separate Tab named "Subscribe"?
Newsletter HTML:
<form method="POST" name="google-sheet">
<input type="text" name="subscribeEmail" placeholder="Your Email Address">
<div class="gold-button small">
<button type="submit">Submit →</button>
<span class="bttn-border left virticle"></span>
<span class="bttn-border right virticle"></span>
<span class="bttn-border top horizontal"></span>
<span class="bttn-border bottom horizontal"></span>
</div>
</form>
Script I'm using for Reservation Form:
<script>
const scriptURL = 'https://script.google.com/macros/s/AKfycbzJA2cZGROFNCwLuPnJjECW21zXMZs8nT4Xo0Nzjy5ETlOVQ3gHgyjE3wzzmHky_0I_/exec'
const form = document.forms['google-sheet']
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.catch(error => console.error('Error!', error.message))
})
</script>
If it were me, I'd have to tackle it like this:
HTML:
<form action="https://script.google.com/macros/s/[SCRIPT ID]/exec" method="post">
<input type="text" name="subscribeEmail" placeholder="Your Email Address">
<div class="gold-button small">
<button type="submit">Submit →</button>
<span class="bttn-border left virticle"></span>
<span class="bttn-border right virticle"></span>
<span class="bttn-border top horizontal"></span>
<span class="bttn-border bottom horizontal"></span>
</div>
</form>
Apps Script:
function doPost(e) {
var ss = SpreadsheetApp.openById("SHEET ID");
var sheet = ss.getSheetByName("Subscribe");
// or use getRange().setValue() if something specific
sheet.appendRow([e.parameter.subscribeEmail])
}
Reference:
Run Google App Script from web page

Search area in Jquery for searching in a grid of input from another input

I wish to search from an input (type="text") in a grid (like table but made in .css for be responsive so with div ans span in html) if input (type="text"). (I precise than this grid in imported from sql sever by php). I don't knw what wrong in my code but it's hide evreything.
I tried http://jsfiddle.net/FranWahl/rFGWZ/ by modifing of course what I needed (so #search by #searchName; table tr by .grid ->class of my div(s); td by span and .text() by .val()-> actually I tried both )
//so here my .js
$(function() {
$("#searchCode").on("keyup", function() {
var value = $(this).val();
$(".grid").each(function(index) {
if (index !== 0) {
$row = $(this);
var id = $row.find("span:nth-child(1)").val();
if (id.indexOf(value) !== 0) {
$row.hide();
}
else {
$row.show();
}
}
});
});
});
//here my php
<form action="menu.php?Option=SelectIgr" method="post">
<div id="titleRow" class="grid">
<span class="cellCode titleCell"><button name="order" class="titlebutton" type="submit" value="orderByCode">Code</button></span>
<span class="cellName titleCell"><button name="order" class="titlebutton" type="submit" value="orderByName">Name</button></span>
<span class="cellEdit titleCell">Edit</span>
<span class="cellDelete titleCell">Delete</span>
</div>
</form>
<?php foreach($ingredients as $object)
{ ?>
<form method="post" id=<?=$object->code()?>>
<div class="grid">
<span class="cellCode"><input type="text" name="code" value=<?=$object->code()?>></span>
<span class="cellName"><input type="text" name="name" value=<?=$object->name()?>></span>
<span class="cellEdit"><button class="ButtonEdit" type="submit" formaction="/action_edit.php"></button></span>
<span class="cellDelete"><button class="ButtonDelete" type="submit" formaction="/action_delete.php"></button></span>
</div>
</form>
<?php } ?>
I expected that in live it would hide line that I don't whant like here http://jsfiddle.net/FranWahl/rFGWZ/ but it's hide everything (like if it didn't show the value on id
Omg I am so st**id today, I should sleep, for those which didn't seen the solution : I attribut my classes to span instead of input facepalm and i try to take the values of the span instread of the input.
Sorry

Firefox saves password but chrome not saving password for login form

For my login form firefox saves but chrome not prompting the "save password" box. I have tried by adding autocomplete="on" but it is not working. Can any one suggest me the answer. I didn't want to use any extention.My code is given below.
<form spellcheck="false" autocomplete="on" id="login-form" action="/user/login/do-login" method="post">
<div class="separator-bar"></div>
<div class="credentials-container">
<div class="username-container">
<div class="label">Email/Username: </div>
<div class="field">
<input class="wx-input" type="text" name="<?php echo $this->escape(App_Api_User::ARG_USERNAME)?>" value="<?php if(isset($this->username)) {echo $this->username;}?>" spellcheck="false"/>
</div>
</div>
<div class="password-container">
<div class="label">password: </div>
<div class="field">
<input class="wx-input" type="password" name="<?php echo $this->escape(App_Api_User::ARG_PASSWORD)?>"/>
</div>
</div>
</div>
<div class="separator-bar bottom"></div>
<div class="forgot-password-container">
<div class="text">forgot password: </div>
<div class="password-page button"><a class="loginForgotPassword" href="#">CLICK HERE</a></div>
</div>
<div class="submit-container">
<input class="login button disabled" type="submit" name="submit" value="GO" />
</div>
<div id="infoMessageContainer">
</div>
<div class="general-error"></div>
</form>
$('body').on('click', '.submit-container .login', function(e) {
if ($(this).hasClass('disabled')) {
e.preventDefault();
e.stopPropagation();
}else{
var self = this;
self.submit();
}
});
_success: function()
{
window.location.href = '/user';
}
All browsers use heuristics for knowing when to save passwords. I'm familiar with Firefox and Chrome. The heuristic they use seems to be:
The form must have a password field
The text input just before the password field is assumed to be the user name
Only those two input fields are saved. Firefox then prompts you that
it can remember your changed password when you fill out a form with two password fields.
Here is a list of things that I typically see break these algorithms:
Sites that use autocomplete=off (specifically requesting that
browsers not remember passwords)
Separating login into multiple pages where the user name is entered on one page and the password is entered on the next.
Using Javascript to copy the contents of these fields into hidden
fields in a hidden form and then submitting the hidden form rather
than the visible form
Requiring more than two fields to be filled out such as
User name, SSN, and password
Username, password, and PIN
Changing the names of the username and password fields
periodically (causes firefox to no longer be able to fill in the
password, even when it is remembered).
I have made lots of changes and then finally works with below block of code.
Hope it will help someone. You need to submit form with this code.
var winNav = window.navigator,
isIOSChrome = winNav.userAgent.match("CriOS");
var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
//Use below if statement, if you want to run only in chrome
if(isChrome || isIOSChrome){
$('#login-form').submit(function () {
if(-1 !== this.action.indexOf('/login')) {
var jForm = $(this);
$.post(this.action, $(this).serialize(), function (data) {
if (data.success == true) {
jForm[0].action = '/user';
jForm.submit();
}
});
return false;
}
});
}

Wanted to make textarea with text editor set to required but won't work

I created a simple page with textarea with condition that it should be required when the textarea is empty.
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2"></label>
<div class="controls">
<textarea class="cleditor" id="textarea2" rows="3" name="isi_visimisi" required><?php echo $data['isi_visimisi'] ?></textarea>
</div>
</div>
When I press submit button with condition that the textarea is empty, it doesn't show any alert that the textarea need to be filled
This might get you started:
$('textarea').blur(function(){
if (this.value.length) $(this).removeAttr('required');
else $(this).attr('required', 'required');
});
$('button').click(function(){
var attr = $('textarea').attr('required');
if (typeof attr == 'undefined' && attr !== false) alert('No required attribute');
else alert('Textarea has required attribute');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2"></label>
<div class="controls">
<textarea class="cleditor" id="textarea2" rows="3" name="isi_visimisi" >Default text in field</textarea>
</div>
</div>
<button>TEST: Does textarea have required attribute?</button>
If it has any content, including whitespace, it will pass the check. Is $data['isi_visimisi'] a string with any length at all?
Also, you must have a submit button for this to work. If you're submitting the form via JavaScript or some other means, the HTML5 required keyword won't work.
It seems you are using CLEditor. The editor set the initial textarea as hidden and provides its own html to build the text editor. When you submit your form, the alert is attached to your hidden textarea, so you can't see it.

How to remove button after submit form using PHP

I need one help.I need to totally remove the submit button after submit the form and when it will be submitted the button will display to user.I am explaining my code below.
<form name="billdata" id="billdata" enctype="multipart/form-data" method="POST" onSubmit="javascript:return checkForm();" action="complain.php">
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px"> Name :</span>
<input type="text" name="u_name" id="name" class="form-control" placeholder="Add Name" onKeyPress="clearField('name');">
</div>
<input type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit"/>
</form>
complain.php:
require_once("./include/dbconfig.php");
if(isset($_REQUEST['complainSubmit']))
{
// ......data is collecting here....
}
when data are submitted successfully the below part is executing.
<script type="text/javascript">
var phpVar = "<?php echo $_GET['success'];?>";
//console.log('php',phpVar=='');
if(phpVar == 1 && phpVar!=''){
alert('Submitted successfully.');
//var subButton=document.getElementById('addProfileData');
//subButton.disabled=false;
}
else if(phpVar == 0 && phpVar!=''){
alert('Unable to add.\\nTry again.');
}
else{
// nothing
}
</script>
<script>
function checkForm(){
var s=document.billdata;
if(s.u_name.value==''){
alert('Please enter name');
s.u_name.focus();
s.u_name.style.borderColor = "red";
return false;
}
}
</script>
Here i need to button hide when the data is going to submit and it will again display after the submit.Please help me.
A javascript code such as:
document.getElementById("your_div").innerHTML = "";
will erase the content of your div.
So, byt tagging the entire form, then erasing its contents, you can "hide" it.
Why you dont add a hide CSS-Selector or remove it by checking via if-statement?
CSS-Version:
<input type="submit" class="btn btn-success <?php ($isSubmitted ? ' hideme' : '')?>" name="complainSubmit" id="addProfileData" value="Submit">
Except a new CSS-Selector: .hideme { display:none }
Via PHP/Template:
html...
<?php if(!$isSubmitted) : ?>
<input type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit">
<?php endif; ?>
html...
Dont forget: You dont need close input html-tag: <input/> just <input>
And what is wrong to hide the button via JS?
document.getElementById("addProfileData").style.display = "none";
UPDATE:
Prompt hiding after clicking:
<button onclick="javascript:this.style.display='none'">
Submit Button
</button>
in your example:
<input onclick="javascript:this.style.display='none'" type="submit" class="btn btn-success" name="complainSubmit" id="addProfileData" value="Submit"/>

Categories