Adwords Conversion Tracking in PHP Form - javascript

I have a html page with contact form. If someone fills the form, they see the "Thanks" message on the same page. HTML code for the page is
<form id="contact" method="post" action="demo">
<div class="row-fluid">
<div class="span6">
<input type="text" required placeholder="First Name" name="Firstname" />
</div>
<div class="span6">
<input type="text" required placeholder="Last Name" name="Lastname" />
</div>
</div>
<div class="row-fluid">
<div class="span6">
<input type="email" required placeholder=" * Email" name="Email" />
</div>
<div class="span6">
<input type="text" required placeholder="Country" name="Country" />
</div>
</div>
<div class="row-fluid">
<div class="span6">
<textarea name="comment" required placeholder="comment" size="100%"></textarea>
</div>
</div>
<div class="row4">
<input type="submit" data-loading-text="Loading..." class="btn button animated bounceIn" value="request information">
</div>
</form>
and the php code is
if ($Email=="") {
echo "<div class='alert alert-error'>
<a class='close' data-dismiss='alert'>×</a>
<strong>Warning!</strong> Please enter your email.
</div>
";
}
elseif ($firstName=="" or $lastName=="" or $country=="") {
echo "<div class='alert alert-error'>
<a class='close' data-dismiss='alert'>×</a>
<strong>Warning!</strong> Please fill all the fields.
</div>";
}
else{
mail($to, $subject, $msg, "From: $_REQUEST[Email]");
echo "<div class='alert alert-success'>
<a class='close' data-dismiss='alert'>×</a>
<strong>Thank you for your message!</strong>
</div>
";
}
Now I would like to integrate Google Adwords conversion code with the contact form. Could someone please assist me on this? Here is my conversion code:
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 955016975;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "_3SsCJzniVwQj86xxwM";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/955016975/?label=_3SsCJzniVwQj86xxwM&guid=ON&script=0"/>
</div>
</noscript>

Related

How to convert HMAC_SHA256_MAC in PHP

index.php
<form class="row g-3" action="<?php echo base_url('signin'); ?>" method="post" id="loginForm" onsubmit="return hashpass();">
<div class="col-12">
<label for="inputUsername" class="form-label">Username</label>
<input type="text" class="form-control" name="uname" id="uname" placeholder="Enter Username" required>
</div>
<div class="col-12">
<label for="inputChoosePassword" class="form-label">Password</label>
<div class="input-group" id="show_hide_password">
<input type="password" class="form-control border-end-0" name="password" required id="password" value="12345678" placeholder="Enter Password"> <i class='bx bx-hide'></i>
</div>
</div>
<div class="col-12">
<div class="d-grid">
<button type="submit" id="signin" class="btn btn-primary" onclick="hashpass();"><i class="bx bxs-lock-open"></i>Sign in</button>
</div>
</div>
</form>
<script src="<?php echo base_url(); ?>/assets/js/HmacSHA256.js"></script>
<script>
function hashpass(){
var FormName='loginForm';
document.forms[FormName]["password"].value=HMAC_SHA256_MAC("aSm0$i_20eNh3os", document.forms[FormName]["password"].value);
return true;
}
</script>
Home_Controller.php
public function signin()
{
$userModel = new UserModel();
$uname = $this->request->getPost('uname');
$password = $this->request->getPost('password');
$data = $userModel->signin($uname);
foreach($data as $key=>$value)
{
$auth_id=$value->auth_id;
$s_password=$value->password;
}
if(!empty($data))
{
if(password_verify($password, $s_password))
{
$session->set('auth_id',$auth_id);
$this->response->redirect(base_url('dashboard'));
}else{
$this->response->redirect(base_url());
}
}
else
{
$this->response->redirect(base_url());
}
}
If I get value from front end suppose value is demo enter from front end then get in controller If I print $2y$10$nxdb2IIIu0QMcXH0T0q0buKcugSUNT3muDOmelBO.fjTE5D8OrICq. So now without this script I want $2y$10$nxdb2IIIu0QMcXH0T0q0buKcugSUNT3muDOmelBO.fjTE5D8OrICq this output using PHP function.
Here is the php exmple.
<?php
echo hash_hmac('sha256', 'data', 'secret');
?>
Update the JS script
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha256.js"></script>
<script>
function hashpass(){
var FormName='loginForm';
document.forms[FormName]["password"].value=CryptoJS.HmacSHA256(document.forms[FormName]["password"].value, "aSm0$i_20eNh3os");
return true;
}
</script>
You can check the link.
Hash HMAC

i have problem with my javascript on codeigniter, parse to javascript

i have some problem, i want to push my data to form html with javascript obj but it can't push with id
this is my javascript
{if {form_case} == ubah}
<script type="text/javascript">
var data={data_by_id};
for (var obj in data)
{
alert(data[obj]);
$("#" + obj).val(data[obj]);
}
</script> {/if}
this my form html
<form class="form" form-case="{form_case}">
<div class="form-group">
<label for="Nama">Nama</label>
<input type="text" class=" riset form-control" id="nama_user" name="nama_user" placeholder="">
<div>
<?php print form_error('nama_user', '<small class="text-danger">', '</small>') ?>
</div>
</div>
<div class="form-group">
<label for="Username">Username</label>
<input type="text" class="form-control" id="username" name="username">
<div>
<?php print form_error('username', '<small class="text-danger">', '</small>') ?>
</div>
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="password" class="form-control" id="password" name="password">
<div>
<?php print form_error('password', '<small class="text-danger">', '</small>') ?>
</div>
</div>
<div class="form-group">
<div class="float-right">
<button class="btn btn-sm btn-primary" name="simpan" data-link="{base_url}/{lvl_auth}/{base_class}/store">Simpan</button>
<button type="reset" class="btn btn-sm btn-success" name="reset">Reset</button>
</div>
</div>
</form>
this my result in inspect element
enter image description here
then this ini my result on html it can't show the value in field
enter image description here

In form1 login page input email field values how to display same email id in form2 email input field without refresh the page

In form1 login page input email field values how to display same email id in form2 email input field without refresh the page while click the forgot button please any one help me.below i attched the screenshot
script
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$(document).ready(function () {
var currentActiveId;
if (sessionStorage.getItem("activeDiv")) {
currentActiveId = sessionStorage.getItem("activeDiv");
$('.form-div').removeClass("active");
$('#' + currentActiveId).addClass("active");
}
$('#btn-show-signup').click(function () {
$('.form-div').removeClass("active");
$('#signup-form').addClass("active");
currentActiveId = "signup-form";
sessionStorage.setItem('activeDiv', currentActiveId);
});
$('.btn-show-login').click(function () {
$('.form-div').removeClass("active");
$('#login-form').addClass("active");
currentActiveId = "login-form";
sessionStorage.setItem('activeDiv', currentActiveId);
});
$('#btn-show-forgot').click(function () {
// $('#forgot-email').attr('value', null);
$('.form-div').removeClass("active");
$('#forgot-form').addClass("active");
currentActiveId = "forgot-form";
sessionStorage.setItem('activeDiv', currentActiveId);
});
});
</script>
form1
<div class="form-main">
<form action="<?php echo base_url(); ?>Index.php/Login_cntrl/login" method="POST" >
<div class="field-wrap">
<label class="view-label">Email Address</label>
<input type="email" placeholder=" Email Address" name="email" id="email" class="input-control" value="<?php echo set_value('email'); ?>"/>
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<div class="field-wrap">
<input type="password" placeholder="Password" name="password" id="password" value="<?php echo set_value('password'); ?>" />
<span class="text-danger"><?php echo form_error('password'); ?></span>
<a href="javascript:void(0)" class="btn btn-link btn-nobg" id="btn-show-forgot" >Forgot ?</a>
</div>
<div class="field-wrap">
<button type="submit" class="btn btn-submit" name="ulogin" id="ulogin" >Login</button>
</div>
<div class="field-wrap">
NEW User? Sign up
</div>
</form>
</div>
form2
<div class="form-div" id="forgot-form">
<div class="form-aside">
<h4 id="form-header">Forgot password </h4>
<p class="form-text"></p>
</div>
<div class="form-main">
<form action="<?php echo base_url(); ?>Index.php/Login_cntrl/ResetPassword" method="POST">
<div class="field-wrap">
<input type="text" name="emaill" id="emaill" placeholder="Enter your Mobile/Email Address" value="<?php echo $this->session->userdata('findemaill'); ?>" autocomplete="off" id="forgot-email"/>
</div>
<div class="field-wrap">
<input type="text" name="otp" id="otp" placeholder="Enter OTP" value="<?php echo set_value('otp'); ?>"/>
<span class="text-danger"><?php echo form_error('otp'); ?></span>
</div>
<?php echo $this->session->flashdata('passwordmissmatch'); ?>
<div class="field-wrap">
<input type="text" name="newpassword" id="newpassword" placeholder="Enter new Password" value="<?php echo set_value('newpassword'); ?>"/>
<span class="text-danger"><?php echo form_error('newpassword'); ?></span>
</div>
<div class="field-wrap">
<input type="text" name="confirmpassword" id="confirmpassword" placeholder="Re-enter new Password" value="<?php echo set_value('confirmpassword'); ?>"/>
<span class="text-danger"><?php echo form_error('confirmpassword'); ?></span>
</div>
<div class="field-wrap">
<button type="submit" name="resubmit" id="resubmit" class="btn btn-submit">submit</button>
</div>
<?php echo $this->session->flashdata('success_msg'); ?>
<div class="field-wrap">
<a href="javascript:void(0)" class="btn-show-login btn btn-link btn-nobg" >Back</a>
</div>
</form>
</div>
</div>
on form1 html
function onClickHandler(){
location.href = 'form2.html?username=' + document.getElementById('TextBoxName').value;
}
on form2 html
function parseQueryString()
{
var queryDict = {}
location.search.substr(1).split("&").forEach(function(item) {
queryDict[item.split("=")[0]] = item.split("=")[1]
});
return queryDict;
}
function onLoadHandler(){
document.getElementById('TextBoxName').value = parseQueryString().name;
}

click the forgot link email field should be validate using javascript

click the forgot link email field should be validate using javascript,i have a done code any mistake please suggest me,below shown javascript code link may be conflict go through once and suggest me
<form id="form1" name="form1" action="<?php echo base_url(); ?>Index.php/Login_cntrl/login" method="POST" >
<div class="field-wrap">
<label class="view-label">Email Address</label>
<input type="email" placeholder="Email Address" name="email" id="email" class="input-control" value="<?php echo set_value('email'); ?>"/>
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<!--<div id='errorDiv' class='col-xs-12 pull-right'> </div>-->
<div class="field-wrap">
<input type="password" placeholder="Password" name="password" id="password" value="<?php echo set_value('password'); ?>"/>
<span class="text-danger"><?php echo form_error('password'); ?></span>
<a href="javascript:void(0)" class="btn btn-link btn-nobg" id="btn-show-forgot" >Forgot ?</a>
</div>
<!--<div id='errorDivv' class='col-xs-12 pull-right'> </div>-->
<div class="field-wrap">
<button type="submit" class="btn btn-submit" name="ulogin" id="ulogin" value="ulogin" >Login</button>
<?php
if (isset($message)) {
echo $message;
}
?>
</div>
<div class="field-wrap">
NEW User? Sign up
</div>
</form>
javascript
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/testing.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<!-- Did you omit follow library? -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<script>
$(document).ready(function() {
$("#form1").validate({
rules: {
email: "required"
},
messages: {
email: "Please specify your name"
}
})
$('#btn-show-forgot').on('click', function() {
$("#form1").valid();
});
});
</script>
It should be:
<script>
$(document).ready(function() {
$("#form1").validate({
rules: {
email: "required"
},
messages: {
email: "Please specify your name"
},
submitHandler: function(form){
form.submit();
}
});//validate()
});
</script>
submitHandler is called when the form is validated successfully. So, here we are submitting the form once it has validated successfully.

html form,db submission,empty data on refresh or back

I have a from submitting data to db,and after entering in to db thank you message comes,everything is in same page.the problem is wheni refresh or go back the same data or empty data is entered in to db. Please help`
<?php
$myServer = "localhost";
$myUser = "root";
$myPass = "";
$myDB = "sample";
$name=$_POST['fname'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
//connection to the database
$dbhandle = mysql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mysql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//echo "$myDB";
//Insert data into db
mysql_query("INSERT INTO reg(name,mobile,email) values ('$name','$mobile','$email')");
/* echo "$name";
echo "$mobile";
echo "$email"; */
//header("location:thank.html");
?>
<!doctype html>
<html>
<head>
<title>Basic form with validation</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="all"/>
</head>
<body>
<div style="width:300px; background:#19a3d1;margin:0 auto;height:200px;">
<?php
if(empty($_POST))
{
?>
<form name="myform" id="frm1" action="index.php" method="post" style="margin:0 auto;"onsubmit="return(validate());">
<h1 style="text-align:center">Form</h1>
<div style="display: table; margin:0 auto;">
<div style="display: table-row;">
<div style="display: table-cell;padding:5px;">
<label>Name</label>
</div>
<div style="display: table-cell;">
<input type="text" name="fname" id="fname" placeholder="Name" />
</div>
</div>
<div style="display: table-row;">
<div style="display: table-cell;padding:5px;">
<label>Mobile</label>
</div>
<div>
<input type="text" name="mobile" id="mobile" placeholder="Mobile" />
</div>
</div>
<div style="display: table-row;">
<div style="display: table-cell;padding:5px;">
<label>Email</label>
</div>
<div>
<input type="text" name="email" id="email" placeholder="Email" />
</div>
</div>
<div style="display: table-row;">
<div style="display: table-cell;padding:5px;" ></div>
<div style="display: table-cell;padding:5px;"><input type="submit" value="Submit"></div>
</div>
</div>
</form>
<?php
}
else{
?>
<div id="thank" >
<span style="color:#ff0000;padding:30px;text-align:center;display:block;">Thank you!!</span>
</div>
<?php
}
?>
</div>
<script src="js/main.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</body>
</html>`
Give name of your submit button.
Like
<input type="submit" value="Submit" name="btnSubmit">
And Write PHP Code like this :
<?php
......
......
if(isset($_POST['btnSubmit']))
{
Your code....
}
?>
Or
You can use ajax to submit the form data.
http://www.formget.com/submit-form-using-ajax-php-and-jquery/

Categories

Resources