Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts

    pass var to another page

    Hi,
    dont get it, thought was easy but cant make it work.

    I have a calculator script which at this moment calculate on the same page using php and # (the page refreshes and jumps to a point in the page.
    On every page a var is declared manually like this:
    $propiedad="name_of_property";

    I am trying to add hijax to the calculator, so I need to point the form thats included in the page to another page, or point to another page in the javascriptfile if I do it another way (prefered as the non ajax version would be displayed on same page also), the problem none of the ways work as I dont have the property var passed to the result page, I been trying everything but I just cant find out how to pass the var. And the value of the var cant be defined as it is diferent on each page, I need to pass the var $propiedad with the value thats on each page using the form, the javascript file and as a last option sessions as I dont like them.
    Any help would be appreciated.
    I have researched and tried but cant manage.
    Thanks

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,346
    Thanks
    60
    Thanked 527 Times in 514 Posts
    You can either pass it in the url - www.yoursite.com/index.php?propid=<value> or you can put it in a form and post it.

    Then you need to get it from either the $_GET (url) or $_POST (form) arrays.

    IF you need that same value to be available on multiple pages then store it in the $_SESSION array instead. Be sure to use session_start() at the top of each script that uses the $_SESSION array.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    You can either pass it in the url - www.yoursite.com/index.php?propid=<value> or you can put it in a form and post it.

    Then you need to get it from either the $_GET (url) or $_POST (form) arrays.

    IF you need that same value to be available on multiple pages then store it in the $_SESSION array instead. Be sure to use session_start() at the top of each script that uses the $_SESSION array.
    Thanks, will try the url one, but not sure that is good, how do I do in the form as I dont have the value? sorry but been trying for hours and nothing.
    Session I think unnesesarry as the same form are included on all pages.
    Thanks in advance if you can give an example, please.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,346
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Unless you have code to show us so that we can see what you're trying to acheive, its difficult to know what sort of example to provide really.

    What code do you have so far?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    New Coder
    Join Date
    Oct 2011
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Unless you have code to show us so that we can see what you're trying to acheive, its difficult to know what sort of example to provide really.

    What code do you have so far?
    The php script is a very long script with many ifs and else so I want past that.
    On the property pages I have the var $propiedaded written manually
    like this $propiedad="name_of_property"; this var changes on all pages.
    This I have in pages where the form is:
    <div id="output">
    <div id="output2">
    <div class="calculator">
    <script src="ao.js" type="text/javascript"></script>
    <script src="hijax2.js" type="text/javascript"></script>
    <?php
    include("calculateformnew2.php");
    ?>

    </div></div></div>
    Also normally I have the phpquery and result included, however the ajaxscript is diferent.
    The form (in the includes there is a dropdown where you can choose year-month and another for the day, one for arrival and one for departure:

    Code:
    <form method="post" action="calculator4.php">
    		<p class="calculatortext">Arrival: <?php include("includes/day.php"); ?><?php include("includes/month.php"); ?>
    Departure: <?php include("includes/day2.php"); ?><?php include("includes/month2.php"); ?> </p>
    <p>
    <input class="boton" size="10" type="submit" name="enviar" value="Calculate/Check"> 
    </p>
    </form>
    The ajaxfile hijax.js:

    Code:
    var getQuery = function(){
    	var dayllegada = document.getElementById("day").value;
    	var daysalida = document.getElementById("day2").value;
    	var monthllegada = document.getElementById("month").value;
    	var monthsalida = document.getElementById("month2").value;
    	return "ajax=true&day=" + encodeURI(dayllegada) + "&day2=" + encodeURI(daysalida)
    	"&month=" + encodeURI(monthllegada) "&month2=" + encodeURI(monthsalida);
    }
    var setQuery = function()
    {
    	var frm = document.getElementsByTagName("form")[0];
    	    frm.onsubmit = function(){
    			var query = getQuery();
    			myHijax(query);
    			return false;
    		}
    }
    
    var myHijax = function(qs)
    {
    	var x = 	new AO("calculator4.php",qs);
    		x.onload = function()
    		{
    			if (x.init && x.status == "200")
    				x.putHere("output");
    		}
    		x.post();
    	return false;
    }
    
    window.onload = function(){
    	var bSupport = new AO();
    	if (bSupport.init) { // test for support of Ajax
    		setQuery();
    		bSupport = null;
    	}
    	else return false;
    }
    As you can see the script is in calculator4.php so I need to pass the var there.
    Thanks in advance

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,346
    Thanks
    60
    Thanked 527 Times in 514 Posts
    So you could do this then?
    new AO("calculator4.php?param=value",qs);

    Then in calculator4:
    $Param = $_GET['param'];
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    New Coder
    Join Date
    Oct 2011
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    So you could do this then?
    new AO("calculator4.php?param=value",qs);

    Then in calculator4:
    $Param = $_GET['param'];
    I did not get it to work, suppose I do it not correctly,
    anyway I managed to pass with the form in a hidden field

    However cant get the ajax to work, suppose as the query is very complicated with several if and else


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •