0
In the form below, I ran tests with the blank fields, but the function validate
does not seem to be called.
In addition, the PHP program (if(isset($_POST['register']))
) will only run if the event onsubmit
(calling the Javascript function) return true
? Anyway the script should not return an alert (regardless of whether the program runs or not)?
function validate(form) {
fail = validateForename(form.f_name.value);
if (fail == "") { return true; }
else { alert('fail'); return false; }
};
function validateForename(field)
{
if (field == "") { return "No Forename was entered.\n"; }
else {
return ""; }
};
<body>
<form action="" method="post">
<input type="text" id="f_name" name="f_name" placeholder="Nome">
<input type="submit" value="Register" name="register" onsubmit="return validate(this)" class="aa-browse-btn">
</form>
</body>
<?php
if(isset($_POST['register'])){
$c_fname = $_POST['f_name'];
$insert_c = "insert into customers (customer_fname)
values ('$c_fname'')";
?>
onsubmit is a form attribute not of the Ubmit input. Since apparently you have a php script too, create a <form></form> and place your Submit as an attribute of it. In addition, there are other minor errors that you will need to fix.
– user142154
thank you for answering. It is not clear, it is at experimental level.
– Ivan Zanoth