Joomla Jforms page_url issue - javascript

Tried to retrieve page url (Jforms EMAIL option) after form submission but form_data:page_url
variable doesn't produce any output at the email.
form_data:page_title doesn't either. There is a Javascript which I believe retrieve URL. I have tried to use Alert(vhref) at the bottom of the script and it return URL pointing to the existing form at the popup window. I need it to be URL of submission result form which is automatically appear (Redirect to->Submitted data 'event') on the screen after form submission. My objective is to have this URL to be included into the email sent. Joomla 3.4.3 , JForms 0.4.4
BR
oleg
<script language="javascript" type="text/javascript">
//Secure the user navigation on the page, in order preserve datas.
var holdForm = false;
window.onbeforeunload = function closeIt(){ if (holdForm) return false;};
jQuery(document).ready(function(){
jQuery("#<?php echo $formHash ?>").validationEngine();
/* var vhref = jQuery(location).attr('href',"submission/submissiondetails/"+"&cid"), */
var vhref = jQuery(location).attr('href'),
vtitle = jQuery(this).attr('title'),
hrefInput = jQuery("#<?php echo $formHash ?>").find('[name="jform[page_url]"]'),
titleInput = jQuery("#<?php echo $formHash ?>").find('[name="jform[page_title]"]');
if(hrefInput.val() == ''){
hrefInput.val(vhref);
}
if(titleInput.val() == ''){
titleInput.val(vtitle);
}
});

Related

create a session using php and ajax

I am beginner in web development so please understand me. I am trying to create a session using php file and call it in javascript using ajax request. but after I input the path of the index.html in address bar, it always shows the index. I want to know how can i possibly do this with javascript and php. restricting the all the pages of the site if there is no user active.
for example logic:
if (userhasValue == true) {
//redirect to index and can access the whole website
} else {
// redirect to login page
}
I have tried the code below but it still redirecting to index.html even if the data recieve in ajax request is empty.
<?php
include('config.php');
session_start();
$user_check = $_SESSION['login_user'];
$temparray = array();
$ses_sql = mysqli_query($db,"select user_id,username,fullname from user where username = '$user_check'");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
if ($row > 0 ){
array_push($temparray, $row); //save your data into array
echo json_encode($temparray);
} else {
echo 'Error';
}
?>
function getUser(){
var user ='';
var fullname ='';
var id ='';
var tempArray = '';
var name = '';
$.ajax({
type:'POST',
url:'../bench/php/session.php',
data:'',
success:function(msg){
alert(JSON.stringify(msg));
let tempArray = JSON.parse(msg)
user = JSON.stringify(tempArray[0]['username']);
fullname = JSON.stringify(tempArray[0]['fullname']);
id = JSON.stringify(tempArray[0]['id']);
document.getElementById('fullname').innerHTML = fullname;
if (msg == 'Error') {
window.location.href = "../pages-login.html";
}
}, error: function(e){
console.log(e);
}, complete: function(c){
console.log(c);
}
});
}
The code above does not restrict the accessibility of the index.html and other pages if the user is not logged in.
I want to restrict the index page and other pages if the user try to redirect to index page without logging in.
Please help me. Any help will much be appreciated! Thanks in advance

Restrict user from visiting a page without logging in using javascript

I have made a register form, from where data is getting stored into the local storage. Only after user logs in successfully, it redirects to success.html or else takes user back to the login page. I have added the following script at the head of success.html-
<script>
if (localStorage.getItem('status') != null)
{
//redirect to page
window.location.href = "success.html";
}
else
{
//show validation message
window.location.href = "login.html"
}
</script>
and following is my login validation function-
//Storing data from local storage into an array of objects
var usersdata = JSON.parse( localStorage.getItem('key_users' ) );
function loginvalidate()
{
usersdata = JSON.parse( localStorage.getItem('key_users' ) );
var usernameinput = document.getElementById("username");
var passwordinput = document.getElementById("password");
for(var p in usersdata)
{
console.log(p+':'+usersdata[p].username+'|'+usersdata[p].email);
if(usernameinput==usersdata[p].username && passwordinput==usersdata[p].password)
{
alert("Logged in successfully");
}
}
jQuery(window).load(function() {
localStorage.setItem('status','loggedIn')
});
}
Here, I am unable to set the status to 'loggedIn' and if I set it manually through console the success.html keeps on loading just like running any infinite loop.
The loop is occurring because of the following condition on the success page. It redirects even when you are at the success page and thus the loop.
if (localStorage.getItem('status') != null)
{
//redirect to page
window.location.href = "success.html";
}
Change it to
if (localStorage.getItem('status') == null)
{
//show validation message
window.location.href = "login.html"
}
P.S. I do highly recommend not to use localstorage to send the username and password to the clientside. It breaks the whole point of authentication and authorization services even existing.

Why html from validation doesn't work?

I have this HTML form and try to validate at client side.
This is the validation function at HTML form.
function registerValidate() {
var have_error = "No";
var email = $('#userEmail').val();
var pwd = $('#password').val();
var pwdr = $('#passwordr').val();
var email_re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*#([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
if (!email.match(email_re)) {
$('#email-error').html('Please enter a valid email');
have_error = "Yes";
}else{
$('#email-error').html('');
}
}
When I click "Create My Account", all texts filled inside the text inputs disappeared and doesn't show the error message, even it should show error message.
What could be wrong?
When do you call this function? On form submit? Maybe you form have been submitted and all data field cleared.
Could you provide source code?

is it possible to use javascript var i= [["j.php?i="+input]]; to send to php?

I am new and just doing practices i just did:
var i= [["j.php?i=1"]]; and it sent value to php and prints but when i want some input from user it does nothing. For example:
file j.js
var input = "hello";
var send= [["j.php?i="+input]];
and in j.php
<?php
$e=$_GET['i'];
echo $e;
?>
Any idea or i am totally wrong? I am trying to have some variation. And i really did with window.location.href. But I just want to know how to do in this way var send= [[]]. Thanks
Edit:
your question is not very clear, maybe try this:
var input = "hello";
var url = "/j.php?i=" + input;
var send = [[url]];
But, it's not clear to me what you want to do with your send variable...
Original
You have to send the data to the server either using a a tag (GET method), a form (POST method) or an Ajax request (any Http verb):
<!-- Here you give a unique id to your link -->
<a id="link" href="">your link</a>
<script>
var i = "Hello";
// wait for page to be loaded
document.addEventListener("DOMContentLoaded", function(event) {
// change the href attribute of the link with the id equal to 'link'
// with whatever data contained in the i variable
// this is done after the page is loaded
document.getElementById("link").href = "/j.php?i=" + i;
});
</script>
Then, when you just click the link, it will send the variable named i containgin the value Hello to your php page.
You could also do it in this way:
<a id="link2">your link</a>
<script>
var i = "HELLO";
// wait for page to be loaded
document.addEventListener("DOMContentLoaded", function(event) {
// here we are telling javascript to change the url
// in the browser when the user clicks the link
document.getElementById('link2').onclick = function() {
window.location = '/j.php?i=' + i
}
});
</script>

Submit hidden form once upon clicking text

I have a set of members who have stored their login credentials (usr | pwd) of other websites as our partners. As is the situation, I am supposed to provide them just a text link and submit a form upon clicking that link.
// Getting values from db and storing them in javascript variables
<script type="text/javascript">
// values from db stored in javascript variables
var at_Cara = "<? echo $at;?>";
var ln_Cara = "<? echo $ln;?>";
var wd_Cara = "<? echo $pw;?>";
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
// I am submitting a form with hidden values, which is as follows:
$(document).ready(function() {
$("#goto").click(function() {
var site = "http://franka.finexp.net/login.aspx";
$('<input>').attr({type: 'hidden',id: 'Auto',name: 'Auto',value: at_Cara}).appendTo('#valgoogexp');
$('<input>').attr({type: 'hidden',id: 'LoginName',name: 'LoginName',value: do_ln_Cara}).appendTo('#valgoogexp');
$('<input>').attr({type: 'hidden',id: 'Password',name: 'Password',value: wd_Cara}).appendTo('#valgoogexp');
$("#valgoogexp").attr("action", site);
$("#valgoogexp").submit();
});
return false;
});
</script>
<a href="javascript:void(0);" id="goto" >Research Tool</a>
<form id="valgoogexp"></form>
The problem is that the form submits twice upon clicking the link. And subsequently the landing page says its a string error.

Categories

Resources