I think i have searched already about tags and yes i am using them already.
But here my question or Idea is:
I have a form including input to search/insert data into database (mysql) (index.php)
form action is being performed on search.php
search box searches input data in the selected tables, if it is found, then it gives the records in result.php, otherwise it inserts the data in table(sql) and then shows it in result.php
I am validating the form/input using javascript on the same page even using tags
Now after loading the index.php page, if someone disable javascript, it shows an alert to reload the page. if someone reload the page, searchbox will hide.
but the problem is, if after loading the page, if someone disable javascript and does not reload the page, and search some restricted text using javascript regex, that text goes into mysql database and it is saved. search.php perform its action and redirect it to result.php
I want some trick in search.php that checks some condition for javascript enabled/disabled, then perform the remaining actions.
IS THERE ANY WAY, IF ACTION SHOULD BE ANOTHER PAGE, on that page is javascript is disabled then it shows nothing, and if it is enabled then redirects to search.php
Form validation on JS level is unimportant, what you need to think about is your php validation. Please read top answers of: form validation with javascript vs php
and this:
How can I prevent SQL injection in PHP?
If you need to check if JS is enabled you can simply make button for your form (but not type="submit" but just a button element). Add event to that button:
onclick="document.getElementById('FormId').submit();"
and your form will be submitted only if JS is enabled as button will use JS for submission
Use a hidden input field and set its value using javascript on form submission. Since the value will be set only using javascript, if the submitted form has an empty value for this field, it can be concluded that javascript was disabled.
Using jQuery:
In the html:
<form id="myformid" action="myactionurl.php" method="POST">
<!-- form fields here -->
<input type="hidden" id="time" name="time" value="">
</form>
In js:
$('#myformid').submit(function(ev) {
$('#time').val($.now());
});
In php:
if(!empty($_POST['time'])) {
//code
} else {
echo "Javascript must be enabled for this site to work.";
}
You don't have to use time, it can be anything.
Related
The "Update" button in WooCommerce Order page randomly stops working and throws the following error in console everytime I click on the button:
An invalid form control with name='' is not focusable.
I read online that it has to do with some hidden but required input fields and HTML5 validation rules. But I went through all the input tags in the source code of the page when the button was not working and didn't find any such "hidden but required" input field.
I am looking for a quickfix right now, so is there anyway I can disable the browser from validating the form inputs, and allow the submit (Update) button to work always?
Any help would be highly appreciated.
Yes, I have also come around this bug while exploring the orders page on woocommerce. So, the workaround would be to loop all the form tags and add novalidate to them.
Fixed it using this script:
var badForms=document.querySelectorAll("form");
for(var i=0;i<badForms.length;i++){
badForms[i].setAttribute("novalidate","novalidate");
}
I have a JSP web application, i use JavaScript to read a value from a saved cookie, let's say it is a login page and if i found the user name and password in the cookie will automatically add the values in the user name and password in their relative HTML input fields so far i can do this easily, however i need to automatically submit the form without clicking on the submit button, how can i fire this click event wither using JavaScript or JSP?
Note: because of very specific business need and using of third party code and architecture i have to implement the scenario as i described, unfortunately can't use servlets or redirect to other pages
am using the following code, which does not work :(
<%!
//JSP code to validate the cookie and get the values
if(true)
{
%>
<!-- JavaScript code -->
<script type="text/JavaScript">
document.forms["myForm"]["buttonSubmit"].click();
</script>
<%!
}
%>
I would like to perform a search via GET from one website's html form to another ASP.net page's form that's on a different webpage. Is this possible?
I want to do this for this website:
http://www.fasnetdirect.com/kaneprls.asp?Page=home
After inspecting element of the search box that says "Search by keywords*" I get the following html tag:
<input type="text" name="SearchString" size="50">
I will have a GET submit form that will query a string over to that search form "Search by keywords*" and have that submitted. So If you search something on my website, it will enter in the string the user typed in on my website, inject it into that "Search by keywords*" input area then automatically hit "search".
Is this possible to do with either PHP, or JavaScript? and if so, what is this called?
So I'm pasting in some code for a form from Salesforce.
This code to be specific: (from the style element to the end of the form) https://gist.github.com/13ab0efd07c2c8cdb3e1
When clicking submit while not filling out any or all fields, I get a form validation check and then a message will popup with the fields that I have not filled out.
However, when I paste the code into our LightCMS template the form validation is not working and just redirects to the thankyou page as if everything went through fine.
They use LightCMS. And even when link to an external js file instead of embedding the js I still get the same results.
I've noticed it adds an "onclick" element on the Submit button on the front-end but it only does that when it's in the CMS not on a bare bones HTML page.
Any thoughts?
i think you should add this
onsubmit=return formvalidator(Document.getElementByid(search-form))
before form action because it will check the form before submitting it. if check fails the action will not occur.
I have a scenario, in this i have to develop pages containing various check box items.
User can select at least one option from that and submit the form.
from the above form, user can select multiple items and proceed to next step.
when user submit form, i have to show next page form data on the basis of user selection.
How can i do that in html and javascript?
or do i need to create this application using php?
(i dont know php)
Can you please suggest me reference links that can i follow to implement this.
You can do it in javascript. On submit, check the checkbox selected and redirect accordingly.
You can do it using javascript. Here's an example form:
<form action="response.html" name="form1" method="GET">
<input type="text" name="param"></input>
<input type="submit" value="submit"></input>
</form>
When you click submit it will redirect to the "action" page you specified, in my case to response.html
In that page the URL will be something like www.mydomain.com/response.html?param=myanswer
You can then pull them apart using javascript e.g.
<script>
document.write(location.search);
</script>
You just have to split this up using methods like 'split', easy to google