Sharkadder Posted September 8, 2008 Share Posted September 8, 2008 Hi, i have a question but not sure if i can do it with javascript or if i'd need php for it. Ok so i have a form which has been created with html, the form itself contains many radio buttons which all have their own value name. Currently when the form is submitted it goes through a javascript procedure, what i would like to do is store the value from the current selected item in the form so that i can later call upon that variable on a seperate page. The form method cannot be changed to $_POST and would like to know how it can be done. To explain a bit more clearly about what i am after, i have 6 radio buttons, each radio button has it's own value e.g. value="value1" etc. how do i get a variable in javascript/php to equal that value and then change if the focus goes onto a seperate radio button? e.g. one that has value="value2". That value will be stored in a variable, then i can later call upon that variable on a seperate page and find out it's value. It might even be better if i had a way to detect what radio button your on when you press the submit button, if that is at all possible. All my radio buttons have the same name "rad" as this is needed as part of my code and i have this code when you click on a radio button: onclick = "ReadForm (this.form, false);" (this being no relevance to you what it does but basically as you can gather i'm telling the readform to switch to false once radio button is clicked) I just basically want to know how to find out what form element you are on once a submit button is pressed, hold the data in a variable, then be able to call upon it on a later page. Would i need to use php, could i just store the value in a cookie or what, if so do i get the value? thanks Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted September 9, 2008 Share Posted September 9, 2008 Best is to use PHP Sesssions. You can use cookies too. Quote Link to comment Share on other sites More sharing options...
Sharkadder Posted September 9, 2008 Author Share Posted September 9, 2008 ok, can somebody move this to the php part of the forum then, i know how to use php sessions but not for in this case, as i don't know how to get values from a form with php without using a method on the form. Thanks. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 9, 2008 Share Posted September 9, 2008 If you are wanting to store the values of the form without actually submitting the form, it cannot be done with only PHP. PHP can only receive a form submission and process the values. If you are wanting to retrieve the values and store them, you will either need to do so with a cookie or via an AJAX request. With the later, you would scrape the values you need and post them to a "save" script that would set your session variables for you. Quote Link to comment Share on other sites More sharing options...
Sharkadder Posted September 9, 2008 Author Share Posted September 9, 2008 Well i got told i can use php sessions to pass values from one page to another, i already knew this but for what i needed it wouldn't work. I could create a cookie but not sure if it would work, here is what i tried with the php sessions for my index.php page: <form action="javascript: void 0;" method="post" onsubmit="<?php session_start(); $_SESSION['value']=$_POST['rad'] ?>;SetDesc (''); SetWt (); SetCode ('a10001'); if (ReadForm (this, true)) CallView (); ClearAll (); return false;"> As you can see i am telling the php session to equal the name rad from the $_POST, however when i go onto my other php page it doesn't seem to work and not sure why, on the next page which it is linked to i have this statement: <?php echo $_GET['value']; ?> Nothing shows when i put ?value after the url, so how would i go about getting the forms value in a cookie and then retreving the value from that cookie on another page using javascript or php as both handle cookies. thanks Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 9, 2008 Share Posted September 9, 2008 Like I said, the PHP gets processed before the markup hits your screen, so you can only process the data with PHP when the form is submitted to the receiving page. If you are wanting to assign the data to a PHP session variable onsubmit, you need to have a JavaScript call that retrieves the data and submits it via an AJAX request to the receiving script that will then assign it to your session. You cannot access PHP after your page has rendered. Quote Link to comment Share on other sites More sharing options...
Sharkadder Posted September 9, 2008 Author Share Posted September 9, 2008 I have never used ajax before, this means i am going to have to look into even more languages which i don't really want to do right now. I understand your trying to suggest things, but i'd really like an example on what i should be doing, once i know how i can get the form value into a cookie or saved into a variable which i can then use on another page, i can do the rest. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.