I have a small problem. I am trying to submit a form to
http://www.fikeandfike.com/propertytax/Grundy/Inquiry.aspx
but it cannot be directly navigate even in browser(i really don't have a clue why?)
to go to above link it is mandatory to click "Parcel enquiry" on
http://www.fikeandfike.com/propertytax/Grundy/MainMenu.aspx?c=32
so i want to click and follow the "parcel enquiry" link using a php script.
if i directly access the former link using cURL i get "Object reference not set to an instance of an object." error
please guide me on how to click and follow the link
To get the same result using PHP you will need to have the Javascript function that is called on clicking 'Parcel Inquiry' in your PHP script, to mimic the result:
HTML for the link in your PHP script:
<a id="ctl00_Main_lnkParcelInquiry" style="color:Blue;" href="javascript:__doPostBack('ctl00$Main$lnkParcelInquiry','')">Parcel Inquiry</a>
JS to define the __doPostBack function and form in your PHP script:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/PropertyTax/Grundy/WebResource.axd?d=k82Y5NDDJDDbxvQs15CYbKKGrXzg8maOqY0bqltbogQI3NDmBuf75gWfcLjILBbAmbWOYgfVPqLiO6Kf2KileNBCke01&t=634622168376055000" type="text/javascript"></script>
And so you will also need that form, <form name="aspnetForm" action="http://www.fikeandfike.com/propertytax/Grundy/Inquiry.aspx">, to exist in your script.
It's just a matter of doing it the same way; so copy the code and the functions and you should get the same results.
Related
I am attempting to submit a form contained in a parent window from a child iframe using jQuery without much luck.
In the child window I have the following validation function:
<script type="text/javascript" src="templates/js/jquery.js"></script>
<script type="text/javascript" src="templates/js/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#form_invoice_item").validate({
submitHandler: function (form) {
// Check if main invoice already saved
if ($('#invoice_id').val() == "") {
// Change target to processing iframe
try {
parent.$('#invoice_form').ajaxSubmit();
} catch(e) { //debug
alert ("Error:" + e);
}
} else {
alert ("Saving invoice " + $('#invoice_id').val() + ' items'); }
//form.submit(); //debug
}
});
});
</script>
<form method="post" id="form_invoice_item" name="form_invoice_item" action="index.php" target="invoice_items">
The error that occurs at parent.$('#invoice_form').ajaxSubmit(); is
Error:TypeError: Object [object Object] has no method 'ajaxSubmit'
If I use the following snippet which is just in plain Javascript, there is no problem(Obviously this isn't jQuery but it gets the job done). How do i do this in jQuery:
parent.document.getElementById('invoice_form').target='process';
parent.document.getElementById('invoice_form').submit();
parent.document.getElementById('invoice_form').target='';
I have a hidden iframe called process which has its display property set to hidden.
If you are in a popup and you want to access the opening window, use window.opener.
Try this:
window.opener.$('#invoice_form').ajaxSubmit();
Instead of this:
parent.$('#invoice_form').ajaxSubmit();
Also see this post.
-------EDIT-----
Don't forget to load jQuery form plugin in those window in which you call it:
<script src="http://malsup.github.com/jquery.form.js"></script>
Just use the parent selector:
$('#invoice_form',window.parent.document)
This should work:
$(parent).find('#invoice_form').submit();
try this..
$(parent).find('#invoice_form').submit();
i have made a login form on a light box using a javascript function. Now i want to store a value on session variable, so to check if the user has logined , and not to show him login lightbox again and again on his navigations on the page.. My javascript function is:
<script language="javascript" type="text/javascript">
function createlightbox()
{
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block'
}
function closelightbox()
{
document.getElementById('light').style.display='none';
document.getElementById('fade').style.display='none'
}
function checksession()
{ if (admin=="admin")
{closelightbox();}
else
{createlightbox();}
}
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.name.value == "admin" && form.password.value == "admin")
{
closelightbox();
var admin = <?php $_SESSION['Admin']= 1; ?>
}
else
{
document.getElementById("error").style.display='block';/*displays error message*/
}
}
</script>
And i m calling the checksession function in my forms onsubmit event as
<form id="Admin" onreset="checksession()">
The problem is, on every reset or submit of form, even on the page changes, the login form is shown. Why it is not checking the check session function.
Please tell me any fault i m making
i'm not sure where your conditions are.
but the following code should present in php script that generates your lightbox:
<?php echo '<script> var admin ='.$_SESSION['Admin'].'</script>'; ?>
(to check above is working correctly, you could View source code of your page and see if there is a line like: <script> var admin =1</script>)
the following should be before you access admin variable setted above:
<script language="javascript" type="text/javascript">
.... //other code
function checksession()
{ if(admin =="admin")
{closelightbox();}
else
{createlightbox();}
}
....
also note that if statement should compare == not assign =
Is it possible to trigger a PHP function by just clicking a link? Or should I stick with the form submit method? If clicking the link will work, where should the link refer to?
Here is a sample code:
<?php
session_start();
function listMe($username){
$username = mysql_real_escape_string($username);
$query = mysql_query("INSERT INTO List (Usernames) VALUES ('$username')") or die(mysql_error());
}
?>
<html>
<head>
<title>SAMPLE</title>
</head>
<body>
Add my username to the list
<?php
listMe($_SESSION['Username']);
?>
</body>
</html>
Maybe someone can point me in the right direction. Thanks!
You can do this by means of loading the entire page over again by the use of form submission, or by loading specific page contents directly into the page without needing to go from page to page. The second method is called "AJAX" (Asynchoronous Javascript and XML). Here are two examples, one of each specified.
Form submission approach
form.php
<?php
function get_users(){
}
if(isset($_GET['get_users']))
{
get_users();
}
?>
...
<form method="get">
<input type="hidden" name="get_users">
<input type="submit">
</form>
AJAX approach
ajax_file.php
<?php
function call_me(){
// your php code
}
call_me();
?>
form.html
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
// do something if the page loaded successfully
}
}
xmlhttp.open("GET","ajax_file.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
click to call function
</body>
</html>
HTML
list me
PHP
<?php
if (isset($_GET['list_me'])) listMe();
(EDIT although this works, it's a bad idea as it is. One should never read from $_GET without sanitising it first)
You can pass it as a query parameter of the link.
http://example.com/?command=listMe&username=tom
However that way everybody will be able to run the function by loading that URL
List me
and in the PHP
<?php
if( isset($_GET['list_me']) && isset($_SESSION['Username'] ) ){
listMe( $_SESSION['Username'] );
}
?>
To trigger a function on link click with php the only way I know would be to append a param in the url of the link and then listen for that
Add my username to the list
Then check for link
if (isset($_GET['function'])){
runFunction();
}
This is because php is a server side technology if you want to fire something without refreshing the page you would need to look at something like javascript
I found this code in a plugin, they have user a foreach look to trigger the action:
$actions = unset($meta[$key]);
foreach ( $actions as $action => $value ) {
echo '<li>' . '<i class="fa fa-times"></i></li>';
}
I have a list list of checkbox with name of files that came froma DB. Then I have button for delete the files. I have the following code for the button:
<input type='button' id='submit_btn' onclick='eraseFile()' value='DELETE FILES' />
and the eraseFile function
...
<script type="text/javascript" language="javascript">
function eraseFile(){
var checekedFiles = [];
$('input:checked').each(function() {
checekedFiles.push($(this).val());
});
alert(checekedFiles); // it gives me all the checked values..good
<?php
echo "HElllo World";
?>
}
</script>
It gives an error "missing ; before statement" and "eraseFile is not defined"
Is it possible to write php inside javascript right??
Is it possible to write php inside javascript right??
Unless the PHP code is generating valid JavaScript, then no.
The reason eraseFile is being called undefined is that your echo statement is causing a syntax error since it is printing the string literal Hellllo World at the end of the JavaScript function which violates JavaScript syntax rules.
Yes, it is possible.
PHP is parsed on the server, so you will literally be printing "HElllo World" inside your javascript function, which would probably cause an error.
You might be looking do do the following:
<?php echo 'document.write("Hello World!");'; ?>
Your PHP output gets appended to your JS function making your javaascript look like this:
<script type="text/javascript" language="javascript">
function eraseFile(){
var checekedFiles = [];
$('input:checked').each(function() {
checekedFiles.push($(this).val());
});
alert(checekedFiles); // it gives me all the checked values..good
HElllo World //syntax error here
}
</script>
You can do this:
<script type="text/javascript" language="javascript">
function eraseFile(){
var checekedFiles = [];
$('input:checked').each(function() {
checekedFiles.push($(this).val());
});
alert(checekedFiles); // it gives me all the checked values..good
alert("<?php echo "HElllo World"; ?>");
}
</script>
This will give a pop-up saying 'Hello World'
To pass a value from your Javascript function to your PHP script, you can do this:
var yourJsVar = {assign value here};
url = "yourPHPScript.php?value=" + yourJsVar;
if (window.XMLHttpRequest)
{ // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = someFunction;
//someFunction will get called when the PHP script is done executing
try
{
req.open("GET", url, true);
}
catch (e)
{
alert(e);
}
req.send(null);
}
else if (window.ActiveXObject)
{ // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req)
{
req.onreadystatechange = someFunction;
req.open("GET", url, true);
req.send();
}
}
In your PHP script:
$yourPhpVar = $_GET['value'];
I mentioned someFunction above that gets called after the PHP script completes execution. This is how it should look. (Note that this is on your Javascript)
function someFunction()
{
if(req.readyState == 4 && req.status == 200)
{
//this will only execute after your AJAX call has completed.
//any output sent by your PHP script can be accessed here like this:
alert(req.responseText);
}
}
Try to echo a meaningful javascript code, "Hello World" it's not a valid JS statement.
Try something like
<?php
echo "alert('HElllo World');";
?>
Where is your eraseFile function defined?
if it is not defined until after the place it is called, you will get that error.
Side note:
You can have php echo inside of the javascript, except what you have there will not do much...
Yes, you can use PHP code in you script files, but your code generate invalid script code here.
<?php
echo "HElllo World"; // becomes: HElllo World (text!) in JS
?>
It is possible to write PHP in Javascript, but it is not the best pratice. The way we normaly do this is through AJAX read the documentation : http://api.jquery.com/category/ajax/
Yes, it is possible to include PHP inside JavaScript, since the PHP will be executed on the server before the page contents are sent to the client. However, in your case, what is sent is the following:
<script type="text/javascript" language="javascript">
function eraseFile(){
var checekedFiles = [];
$('input:checked').each(function() {
checekedFiles.push($(this).val());
});
alert(checekedFiles); // it gives me all the checked values..good
HElllo World
}
</script>
This doesn't validate as JavaScript, since the "Helllo World" is not a valid JavaScript command. This is why the function isn't being defined properly. You need to replace the "Helllo World" string with an actual JavaScript command.
i am trying to use gigya auth properties to login users on my website. They have a function that needs to be called after i authenticate the credentials as seen in this illustration
I have a form and when i submit the form i send it to login.php where i authenticate my users. My question is how do i call socialize.notifyLogin?.
this is the javascript:
<script type="text/javascript"> var conf = { APIKey:'2_9E9r_ojXEqzZJqKk7mRqvs81LtiSvUmBcm' }; </script>
<script type="text/javascript">
var secret = 'eIqtclW2CxC6qvmT55MvOxZ5Rm7V5JhBV/gioJLKIxM=';
var yourSiteUid= '<?php echo $talentnum;?>'; // siteUID should be retrieved from your user management system
function your_b64_hmac_sha1(secret, datePlusSite) {
var b64Sig = ''; // Place your implementation here ...
return b64Sig;
}
function printResponse(response) {
if ( response.errorCode == 0 ) {
alert('After notifyLogin');
}
}
var dateStr = getCurrentTime();
var datePlusSite = dateStr + "_" + yourSiteUid;
var yourSig = your_b64_hmac_sha1(secret, datePlusSite);
var params={
siteUID:yourSiteUid,
timestamp:dateStr,
signature:yourSig,
callback:printResponse
};
gigya.services.socialize.notifyLogin(conf,params);
</script>
to be more clear i set the $talentnum; inside my login.php. so i have the form i send it ti the login.php and a redirect page... Where the call to socialize.notifyLogin will be?
thanks,
any idea helps
You have two options:
If you call login.php as the target of an HTML form, you should redirect the user to a new HTML page upon successful login. This new HTML page should contain the socialize.notifyLogin call.
If you call login.php via an AJAX request, you should call socialize.notifyLogin in the "success" callback of the AJAX request.
In no case, however, will you be able to execute the Javascript function directly from your PHP script. PHP executes on the server before the Javascript is sent to the user as output with your HTML document, and therefore cannot execute Javascript functions directly.
PHP is executed before the page loads, therefore you cannot call a JavaScript function from PHP.