Load Div after Submit Required Fields on PHP Form - javascript

I have a hidden div I am loading on click of submit button. I also have .notShouldBeBlank on the script for the form. What is the right method so that the php sends results and the hidden div will not load until all required fields are complete? It's currently loading the hidden div and sending results as soon as I click submit. What am I doing wrong?
<?php
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$name = stripslashes($name);
$address = stripslashes($address);
$city = stripslashes($city);
$state = stripslashes($state);
$phone = stripslashes($phone);
$email = stripslashes($email);
$to = 'myemail#thisismywebsite.com ' . ', ';
$to .= $Email;
$from = "$Email ";
$subject = 'Look and Learn: Applicant';
$message = <<<EOF
<html>
<body bgcolor="#FFFFFF">
<b>Look and Learn: Applicant</b><br /><br />
<b>Name:</b> $name<br />
<b>Address:</b> $address / $city, $state<br />
<b>Phone:</b> $phone<br />
<b>Email:</b> $email<br />
</body>
</html>
EOF;
//end of message
// Additional headers
$headers .= 'From: Razor Chic of Atlanta <info#thebrlab.com>' . "\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
mail($to, $subject, $message, $headers);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Sign Up</title>
<link rel="stylesheet" href="css/sign-up.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function() {
$('#thankyou').show();
$("#hidden1").html($("#thankyou").html());
});
});
</script>
<script>
$('#myContact').submit(function () {
$.each($('#myContact .notShouldBeBlank'), function()
{
if($(this).val() == ''){
$(this).after('<span class="error">This field is required.</span>');
}
});
// Other groups validated here
}
</script>
</head>
<body style="overflow: hidden; overflow-x: hidden; overflow-y: hidden;">
<div id="wrap">
<div id="hidden1"></div>
<div style="font-size: 18px; font-weight: bold; font-family: Verdana, Geneva, sans-serif;">
Sign-Up: Look And Learn Class
</div>
<br>
<form id="form" action="" name="myContact" onSubmit="return validateForm()" method="post" enctype="multipart/form-data">
<div>
<label>
<span>Name: *</span><br>
<input name="name" type="text" size="64" placeholder="Name">
</label>
</div>
<div>
<table width="100%" >
<tr>
<td width="230">
<label>
<span>Address: *</span><br>
<input placeholder="Address" size="100" type="text" name="address" maxlength="100">
</label>
</td>
<td width="160">
<label>
<span>City *</span><br>
<input placeholder="City" name="city" type="text" id="city" maxlength="100" />
</label>
</td>
<td width="189">
<label>
<span>State *</span><br>
<input placeholder="State" name="city" type="text" id="city" maxlength="3" />
</label>
</td>
</tr>
</table>
</div>
<div>
<label>
<span>Phone: *</span><br>
<input placeholder="Phone" size="64" type="text" name="phone">
</label>
</div>
<div>
<label>
<span>Email: *</span><br>
<input placeholder="Email address" size="64" type="email" name="email">
</label>
</div>
<div>
<button name="submit" type="submit" id="submit">S I G N U P</button>
</div>
</form>
<p>Note: * Fields are required</p>
</div>
<!---- THANK YOU---->
<?php
if($sent){
echo '<div id="thankyou" style="display:block;">';
}
else{
echo '<div id="thankyou" style="display:none;">';
}
?>
<!---- PAY BEGINS ---->
<div id="paynow1-wrapper">
<div id="paynow1">
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="Razorchicofatlanta#gmail.com">
<input type="hidden" name="item_name" value="Look and Learn: Deposit">
<input type="hidden" name="amount" value="100.00">
<input type="hidden" name="return" value="http://thebrlab.com/razor-chic-of-atlanta/thank-you.html">
<input type="hidden" name="undefined_quantity" value="1">
<input style="background: none" onMouseOver="this.src='images/pay-now-up.png'" onMouseOut="this.src='images/pay-now-down.png'" type="image" src="images/pay-now-down.png" height="41" width="141" border="0" alt="Pay Now" class="button">
</form>
</div>
</div>
<!---- PAY ENDS ---->
<!---- PAY BEGINS ---->
<div id="paynow2-wrapper">
<div id="paynow2">
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="Razorchicofatlanta#gmail.com">
<input type="hidden" name="item_name" value="Look and Learn: Balance">
<input type="hidden" name="amount" value="99.00">
<input type="hidden" name="return" value="http://thebrlab.com/razor-chic-of-atlanta/thank-you.html">
<input type="hidden" name="undefined_quantity" value="1">
<input style="background: none" onMouseOver="this.src='images/pay-now-up.png'" onMouseOut="this.src='images/pay-now-down.png'" type="image" src="images/pay-now-down.png" height="41" width="141" border="0" alt="Pay Now" class="button">
</form>
</div>
</div>
<!---- PAY ENDS ---->
<!---- PAY BEGINS ---->
<div id="paynow3-wrapper">
<div id="paynow3">
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="Razorchicofatlanta#gmail.com">
<input type="hidden" name="item_name" value="Look and Learn: Full Payment">
<input type="hidden" name="amount" value="199.00">
<input type="hidden" name="return" value="http://thebrlab.com/razor-chic-of-atlanta/thank-you.html">
<input type="hidden" name="undefined_quantity" value="1">
<input style="background: none" onMouseOver="this.src='images/pay-now-up.png'" onMouseOut="this.src='images/pay-now-down.png'" type="image" src="images/pay-now-down.png" height="41" width="141" border="0" alt="Pay Now" class="button">
</form>
</div>
</div>
<!---- PAY ENDS ---->
<img src="images/thank-you/look-and-learn1.png" />
</div>
<!---- THANK YOU---->
</body>
</html>

Your form ID is "form", not "myContact". Change form id to myContact.
Then you have 2 "onsubmit" events, one in jQuery and the other inline (onSubmit). Try to merge them into one to avoid unexpected behaviors.
Also, make sure you return false on your submit event function if the validation fails, so the submit is halted.
Update 1
JavaScript:
$('#myContact').submit(function () {
$.each($('#myContact .notShouldBeBlank'), function()
{
if($(this).val() == ''){
$(this).after('<span class="error">This field is required.</span>');
return false;
}
});
/* Uncomment the line below if you really have a validateForm() function */
// return validateForm()
}
HTML:
<form id="myContact" action="" name="myContact" method="post" enctype="multipart/form-data">

Related

Closest find a class and change the input value

I have added the hidden field in the form and inserting the data into the database. I have 16 fields on my page and If the user enters any value in the field then I have to change the value from 0 to 1 in the input field.
I tried the below code but it's not working.
$(document).ready(function() {
//Check this link
$(".onchangefield").change(function() {
var val = $(this).closest(".onchangefield").find(".haschange").val(1);
//$(".haschange").val(1);
alert(val);
});
});
<form action="process.php" name="employee" method="post">
<input type="text" name="name" class="onchangefield">
<input type="hidden" name="haschange[name]" class="haschange" value="0" />
<input type="email" name="email" class="onchangefield">
<input type="hidden" name="haschange[email]" class="haschange" value="0" />
<button type="submit" name="save">Save</button>
<button type="submit" name="send_for_approval">Send to approval</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
How to change the value in the foreach.
<?php
$i=1;
$arrayName = array('1','2','3');
foreach ($arrayName as $key => $value) {?>
<input type="file" name="slider[]" class="fileupload onchangefield">
<input type="hidden" name="haschange[slider][<?php echo $i;?>]" class="haschange" value="">
<?php $i++; } ?>
You can use .next() to get the reference of next input and change value there .
Demo Code :
$(".onchangefield").change(function() {
var selector = $(this).next() //get next input..
selector.val($(this).val() != "" ? 1 : 0) //depending on value change value of next
});
<form action="process.php" name="employee" method="post">
<input type="text" name="name" class="onchangefield">
<input type="text" name="haschange[name]" class="haschange" value="0" />
<input type="email" name="email" class="onchangefield">
<input type="text" name="haschange[email]" class="haschange" value="0" />
<button type="submit" name="save">Save</button>
<button type="submit" name="send_for_approval">Send to approval</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

PHP form with script do not do POST

i'm new with web programming and i have this problem, I have this little form:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Orden de Servicio</title>
<link rel="stylesheet" href="css/tabla.css">
<img src="img/logogps.png" alt="GPS" style="float:left; width:64px;height:64px; margin-left:1%;margin-top:1%;">
<script src="scripts/jquery-1.12.4.js"></script>
<script type="text/javascript">
function EnableAnom()
{
if($('#chkanom').is(':checked'))
{
document.getElementById("InputAudio").hidden = false;
document.getElementById("InputText").hidden = false;
document.getElementById("InputImage").hidden = false;
document.getElementById("lblaudio").hidden = false;
document.getElementById("txtdet").hidden = false;
document.getElementById("lblimg").hidden = false;
}
else
{
document.getElementById("InputAudio").hidden = true;
document.getElementById("InputText").hidden = true;
document.getElementById("InputImage").hidden = true;
document.getElementById("lblaudio").hidden = true;
document.getElementById("txtdet").hidden = true;
document.getElementById("lblimg").hidden = true;
}
}
</script>
</head>
<body>
<form action="checkprereg.php" method="POST" enctype="multipart/form-data">
<h2 class="text-center">Check PreInstalación</h2><br /><br />
<input type="hidden" name="id_orden" value=<?php echo $idorden; ?> />
<input type="hidden" name="chkenc" value="0">
<input type="checkbox" name="chkenc" value="1">
<label for="chkenc">Encendido</label><br>
<input type="hidden" name="chkapg" value="0">
<input type="checkbox" name="chkapg" value="1">
<label for="chkapg">Apagado</label><br>
<input type="hidden" name="chkcontig" value="0">
<input type="checkbox" name="chkcontig" value="1">
<label for="chkcontig">Continua / Ignición</label><br>
<input type="hidden" name="chkluces" value="0">
<input type="checkbox" name="chkluces" value="1">
<label for="chkluces">Luces</label><br>
<input type="hidden" name="chkotra" value="0">
<input type="checkbox" name="chkotra" value="1">
<label for="chkotra">Otra</label><br><br>
<label for="videvi">Video de evidencia (arranque):</label>
<input type="file" name="videvi" id="InputFile" accept="video/*"><br><br>
<label for="chkanom">Habilitar registro de anomalías</label>
<input type="checkbox" name="chkanom" id="chkanom" value="1" onclick="EnableAnom()" ><br><br>
<label for="audanom" hidden="true" id="lblaudio">Audio con detalles:</label>
<input type="file" name="audanom" id="InputAudio" accept="audio/*" hidden="true"><br><br>
<label for="textanom" hidden="true" id="txtdet">Detalles:</label>
<textarea name="textanom" id="InputText" rows="5" cols="50" hidden="true"></textarea><br><br>
<label for="imganom" hidden="true" id="lblimg">Imagen con detalles:</label>
<input type="file" name="imganom" id="InputImage" accept="image/*" hidden="true"><br><br>
<button class="button orange" type="submit" value="Submit">Enviar</button>
<button class="button orange" type="reset" value="Reset">Limpiar</button>
</form>
<p>
<a href="menu.php">
<img src="img/home.png" alt="Home" style="float:right; width:64px;height:64px; margin-left:1%;margin-top:1%;">
</a>
</p>
</body>
I did added a litlle script (EnableAnom()) that hides some inputs with a checkbox, but, with this script the form don't do POST, (I receive all vars empty) if I remove the script, the form works ok.
What is wrong in the script? (I did move up script up, down, without success)
Best regards.
<input type="hidden" name="id_orden" value=<?php echo $idorden; ?> />
change to
<input type="hidden" name="id_orden" value="<?php echo $idorden; ?>" />
and test first

Updating multiple hidden fields

I'm trying to update 2 hidden fields of a form based on the checkbox toggle. For some reason, only the first field is getting update and second one doesn't.
Any ideas what am I missing?
echo '
<form id="form1" action="';
echo $paypalURL;
echo '" method="post"> <p></p>';
?>
<input type="hidden" name="business" value="<?php echo $paypalID; ?>">
<input type='hidden' id="item_number" name="item_number" value="1">
Other Amount: <input id="amount" name="amount" value=""> <p></p>
<input type='hidden' id="currency_code" name="currency_code" value="">
<input type="hidden" id="src" value="" name="src" />
<input type="hidden" name="cmd" value="_donations">
Recurring donation?:
<input type="checkbox" id="checkbox" name="checkbox" value="" />
<script type="text/javascript">
var checkbox = document.getElementById('checkbox');
checkbox.addEventListener('change', function()
{
if (this.checked) {
document.getElementById('src').value = '1'
document.getElementById('cmd').value = '_xclick-subscriptions'
}
else
{
document.getElementById('src').value = ''
document.getElementById('cmd').value = '_donations'
}
}, false)
</script>
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='http://localhost/wordpress1/wordpress/cancel.php'>
<input type='hidden' name='return' value='http://localhost/wordpress1/wordpress/success.php'>
<!-- Display the payment button. -->
<p><input type="image" name="submit" border="0"
src="images/PayPal-Donate-Button-PNG-Clipart.png" width="80" hight="50" alt="Donate Now"> </p>
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
It works, you just didn't add id="cmd" to hidden <input>
Your version:
<input type="hidden" name="cmd" value="_donations">
Correct varsion:
<input type="hidden" id="cmd" name="cmd" value="_donations">
Regards, KJ

Checkout Is not working properly in Html webpage

I have a problem in checkout, i included add to cart code in my webpage and it is working but the checkout button is not working. What is the code or link that i should add in the webpage .The java script i am using is http://cdnjs.cloudflare.com/ajax/libs/minicart/3.0.6/minicart.min.js
and the code in webpage is
<form action="" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="example#minicartjs.com" />
<input type="hidden" name="item_name" value="MAVJ10015" />
<input type="hidden" name="amount" value="10.00" />
<input type="hidden" name="currency_code" value="INR" />
<input type="hidden" name="return" value="http://www.minicartjs.com/?success" />
<input type="hidden" name="cancel_return" value="http://www.minicartjs.com/?cancel" />
<input type="image" name="submit" src="images/add to cart.png" class="button" style="margin-left: 73px; margin-top: 6px; height: 21px;"/>
</fieldset>
</form>
here i am using php to process the post data.
the changes i made are
given id to form
given id to button
submit the cart using the jsvascript
$( "#button_id" ).click(function() { $( "#form_id" ).submit(); });
and php code to process the data.
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
print_r($_POST);
echo "</br></br>";
echo "business : ". $_POST['business'];
}
?>
the entire code is here
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<form action="" method="post" id="form_id">
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="example#minicartjs.com" />
<input type="hidden" name="item_name" value="MAVJ10015" />
<input type="hidden" name="amount" value="10.00" />
<input type="hidden" name="currency_code" value="INR" />
<input type="hidden" name="return" value="http://www.minicartjs.com/?success" />
<input type="hidden" name="cancel_return" value="http://www.minicartjs.com/?cancel" />
<input id="button_id" type="image" name="submit" value="submit" src="images/add to cart.png" class="button" style="margin-left: 73px; margin-top: 6px; height: 21px;" />
</fieldset>
</form>
</body>
<script type="text/javascript">
$( "#button_id" ).click(function() { $( "#form_id" ).submit(); });
</script>
</html>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
print_r($_POST);
echo "</br></br>";
echo "business : ". $_POST['business'];
}
?>

How to keep discussions of user in database and show them on view page

I have a problem in my crm application,in my application I have a user view page with his details and a add follow up button in which I have 3 text fields used to maintain follow-up records of a user and show dis follow-up details in view page . How can I achieve it?
Here's my view.php page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php require_once ("sqlremote.php");
$sql="Select * from ac_member order by rand() limit 15";
$res=$db->prepare($sql);
$res->execute();
$row = $res->fetch(PDO::FETCH_ASSOC)
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/default.css"/>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
if(event.button==2)
{
alert(status);
return false;
}
}
</script>
<style>
.top-section{height:87px; padding-bottom:10px;}
.logo{width:266px; height:87px; float:left;}
body {
background-image: url(images/hd_wall_4472.jpg);
</style>
</head>
<body oncontextmenu="return false">
<div class="logo"><img src="images/logo.png" alt="" width="200" height="78" border="0" /></div>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
<form action="process.php" method="post" class="register">
<fieldset class="row1">
<legend>Basic Information</legend>
<p>
<label>Date
</label>
<input name="fname" type="text" readonly="readonly" value="<?php echo $row['datepicker']?>"/>
<label>Full Name
</label>
<input type="text" readonly="readonly" value="<?php echo $row['fname'] ?>"/>
<label>Qualification
</label>
<input type="text" readonly="readonly" value="<?php echo $row['qualification'] ?>"/>
</p>
<p>
<label>Father Name
</label>
<input type="text" readonly="readonly" value="<?php echo $row['gname'] ?>"/>
<label>Email
</label>
<input name="contact" type="text" readonly="readonly" value="<?php echo $row['email'] ?>"/>
<label>Contact
</label>
<input name="contact" type="text" readonly="readonly" value="<?php echo $row['contact'] ?>"/>
</p>
<p>
<label>City
</label>
<input type="text" readonly="readonly" value="<?php echo $row['city'] ?>"/>
<label>Course
</label>
<input type="text" readonly="readonly" value="<?php echo $row['course'] ?>"/>
</p>
<div class="clear"></div>
</fieldset>
</br></br>
<fieldset class="row1">
<legend>Lead Info</legend>
<p>
<label>Lead Source
</label>
<input name="leadsource" type="text" readonly="readonly" value="<?php echo $row['leadsource']?>"/>
<label>Lead Source Type
</label>
<input type="text" readonly="readonly" value="<?php echo $row['leadsourcetype'] ?>"/>
</p>
<p>
<label>Lead Source Detail
</label>
<input type="text" readonly="readonly" value="<?php echo $row['leadsourcedetail'] ?>"/>
<label>Lead Score
</label>
<input name="leadscore" type="text" readonly="readonly" value="<?php echo $row['leadscore']?>"/>
</p>
<div class="clear"></div>
</fieldset>
<fieldset class="row2">
<legend>Followup Details</legend>
<p>
<input type="button" value="Add Followup" onClick="addRow('dataTable')" />
<input type="button" value="Remove Followup" onClick="deleteRow('dataTable')" />
</p>
<table id="dataTable" class="form" border="1">
<tbody>
<tr>
<p>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td>
<label>Followup</label>
<input type="text" required="required" name="BX_NAME[]">
</td>
<td>
<label for="BX_age">Followup Calldisposition</label>
<input type="text" required="required" name="BX_age[]">
</td>
<td>
<label for="BX_gender">Followup Comments</label>
<input type="text" name="BX_gender[]" required="required">
</td>
</p>
</tr>
</tbody>
</table>
<div class="clear"></div>
</fieldset>
<input class="submit" type="submit" value="Confirm »" />
<div class="clear"></div>
</form>
</br>
</body>
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=9046834;
var sc_invisible=1;
var sc_security="ec55ba17";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type='text/javascript' src='" +
scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="free hit
counter" href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/9046834/0/ec55ba17/1/"
alt="free hit counter"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
</html>
Im not sure if i understand your question correct. Is this a database/query related issue or more a strategic question of what is considered best practise?
Im not really sure what youre trying to accomplish here :)
Ah :)
So actually you would grab your data gotten from you select first. Which you are already doing.
process.php:
if ($everythingisok) {
$res=$db->prepare("UPDATE ac_member SET bx_gender='".$_POST["BX_gender"]."', field2=etc... WHERE id = '".$_POST['id']."'");
$res->execute();
}
After storing the data into the table you can add to your html/view:
<input type="text" name="BX_gender" value="<?php echo escape($row['bx_gender']);?>" required="required">
However, i noticed that you are using the brackets in your input name. This will cause that the data coming through is passed as an array. I don't know if you did this on purpose

Categories

Resources