Jump to content

Transfer Variable


user4fun

Recommended Posts

File 1main.php has the variable $mypickmain.php has an iframed file choice.htmChoice.htm is a form that on submit wold run submit.php method="post"submit.php will email the users' choice $mypick in the iframed choice.htmProblemsubmit.php sends the email fine but the $mypick is not transfered.maily because it is in the main.php BUT NOT IN THE choice.htmHow do i transfer the variables to the choice.htm so the submit.php would email $mypick.Sorry if it is confusing.

Link to comment
Share on other sites

i didn't really understood every thing, but you want to transfer variable so use:1. Cookie

<?php setcookie("cookie_name", "$variable", time()+3600); // time - 1 hour?>

and then you get the variable like this:

<?php echo $_COOKIE['cookie_name'];?>

2. Use the URL:

<?php $variable = "Blah";echo "<a href="submit.php?action_name=$variable">Blah</a>";?>

and then you get the variable like this:

<?php echo $_GET['action_name'];?>

You can use session's to:http://www.w3schools.com/php/php_sessions.asp

Link to comment
Share on other sites

You need to use Javascript to get the value from the form in the iframe and add it to the form that you are submitting. You need to use the Javascript DOM to access the other value and save it. It's best to use IDs with everything. You can have your hidden element in your parent form:<input type="hidden" name="choice_val" id="choice_val" value="">Also have an ID on the iframe:<iframe id="choice_frame">And inside that file you need an ID on the element that you want to copy:<input type="text" name="mypick" id="mypick">And then you need to have a Javascript function run when the form gets submitted:<form onsubmit="return copy_value();" ...>The Javascript function would look like this:

function copy_value(){  document.getElementById("choice_val").value = document.getElementById("choice_frame").document.getElementById("mypick").value;}

I think that's how the DOM is setup for an iframe anyway, I might be wrong about how to read the value though.

Link to comment
Share on other sites

maybe there is another way to do this, php file display the list of entries on mysql tablethe php file will display the entries and after that the last clumn has an iframed form. The form includes two radio button. Yes and NoWhen the submit button is hit it would send the value of the chosen button = the $row["$website"] that was pulled form the sqp statment.I need the subvmit button to pick up the value of the $ row along with teh radio buttons.

Link to comment
Share on other sites

A document in an iframe is a separate document from the document with the iframe in it. Even though you might have PHP code in both of them, they aren't connected through PHP in any way. If you want one page to have access to the other page's information, you need to use Javascript since it runs in the browser and not on the server, you are working with the client interface here.This is the tutorial for the DOM:http://www.w3schools.com/htmldom/default.aspThe document object model is what you use to access the value, the document object model is what has the value in it. You can use Javascript to access that and update the other page with it.

Link to comment
Share on other sites

It is a good tutorial, i am learning a few things. Let me ask you this though.I do not want to transfer the value form the iframed page to the main page. Rather i want to pick up a value form the main page itself and put it in the iframed box.The values in the main page are returned fromwhile($row = mysql_fetch_array($result)) .every row echoed will have a box beside it with the form iframed, when the submit button is hit, the form choice will be used along with the $row. How would i use the tutorial to place a javascript and use DOM in a valuble that does not exist yet. sort to speak.Detailsa table is showed with the variables $websitethe second column has a radio button yes and no. The quetion is have you used this site before. The user would input Yes, Or No then hit the submit button. The submit button emails the users choice in clude $Choice (yes/no) the $row['website'] however is outside the iframe?I really need help.lol

Link to comment
Share on other sites

That page is sort of a mess, you've got 4 doctypes and 5 <html> tags in there. Regardless, it's probably not best to use an iframe here. If the point of the iframe is so that they can vote on one item without the page refreshing, AJAX would be a much better (and easier) way to go. Is there a reason why you need to use the iframe?

Link to comment
Share on other sites

Yeah, i have a very good why i am using iframes, i am a rookie, lol

4 doctypes and 5 <html> tags in there
can you tell me what that mean?I did not think this would be so hard. If i was to not use the iframe, and use this AJAX which seems like it does stuff without refreshign the page. What would it look likethe third colunmecho '<td>'then what to produce two radio buttons, a YES AND NO then a submit button, when hit, the page would remain the same and only that cell would change to aecho " Thank you"; and the radio button and the $row['website'] is emailed.
Link to comment
Share on other sites

This is the code for the page you posted:

<html><head>		 <title>I need Help</title></head><body>  <table border='1' align='center'><tr><th>Website</th><th>Email</th><th>is it i-SAFE?</th></tr><td><a href="http://www.ce-coins.com" target="_blank">www.ce-coins.com</a></td><td>info@ce-coins.com</td><td><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>	 <title>Untitled</title></head><body><iframe src="http://www.i-s-a-f-e.com/business/vote_form.htm" style="border:0px black solid;" name="I1" frameborder="0" align="absmiddle" width = "150" marginwidth="1" marginheight="1" height="26" border="0" scrolling="no"></iframe></body></html></td></tr><td><a href="http://www.parscoins.com" target="_blank">www.parscoins.com</a></td><td>info@parscoins.com</td><td><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>	 <title>Untitled</title></head><body><iframe src="http://www.i-s-a-f-e.com/business/vote_form.htm" style="border:0px black solid;" name="I1" frameborder="0" align="absmiddle" width = "150" marginwidth="1" marginheight="1" height="26" border="0" scrolling="no"></iframe></body></html></td></tr><td><a href="http://www.zainostore.com" target="_blank">www.zainostore.com</a></td><td>info@zainobros.com</td><td><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>	 <title>Untitled</title></head><body><iframe src="http://www.i-s-a-f-e.com/business/vote_form.htm" style="border:0px black solid;" name="I1" frameborder="0" align="absmiddle" width = "150" marginwidth="1" marginheight="1" height="26" border="0" scrolling="no"></iframe></body></html></td></tr><td><a href="http://www.itaggit.com" target="_blank">www.itaggit.com</a></td><td>advertising@itaggit.com</td><td><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>	 <title>Untitled</title></head><body><iframe src="http://www.i-s-a-f-e.com/business/vote_form.htm" style="border:0px black solid;" name="I1" frameborder="0" align="absmiddle" width = "150" marginwidth="1" marginheight="1" height="26" border="0" scrolling="no"></iframe></body></html></td></tr></table>The Website Column and Email are pulled form the mysql table. The last column is the iframed form. The choice YES/NO is emailed, but i need the websites value to be picked up to.<br>The website value is in the php code as row['website']</body></html>

You can see all the doctype tags, and all the <html>, <body>, </html>, and </body> tags. A well-formed HTML document should have a structure like this:

<!DOCTYPE ...><html>  <head>	...  </head>  <body>	...  </body></html>

It should only have 1 doctype, html and body tag. All of the content goes inside the body, things like stylesheets and Javascript go in the head.To set up the AJAX, I would have the third column contain a form that uses the AJAX code to submit. The AJAX code would send the request to the server, get a response back, and update the page. So for the third td:

<td>  <form onsubmit="return submit_request(this);">	<input type="radio" name="radio_group" value="1">	<input type="radio" name="radio_group" value="2">	<input type="submit" value="Vote">  </form></td>

The hard part is the submit_request function, which always needs to return false so that the form doesn't actually submit (so Javascript handles everything). You can do a Google search for AJAX tutorials to see how to use the objects to send the request and get the response back, but the function would get the value of the radio button, do the AJAX stuff, then update the page to show a message.

function submit_request(frm){  var val = "";  if (frm.elements.radio_group[1].checked)	val = frm.elements.radio_group[1].value;  else	val = frm.elements.radio_group[0].value;  //val is the value of the radio button they chose  //AJAX request here  //remove the form and show a message  par = frm.parentNode;  par.removeChild(frm);  par.innerHTML = "Thank you";  return false;}

Link to comment
Share on other sites

This is what i have so far, you can lok at it and tell me what you think. The message is not being relpaced to "Thank you"My exact code and please don't laugh, lol

<html><head>		 <title>I need Help</title></head><style>function submit_request(frm){  var val = "";  if (frm.elements.radio_group[1].checked)	val = frm.elements.radio_group[1].value;  else	val = frm.elements.radio_group[0].value;  //val is the value of the radio button they chose  //AJAX request here  //remove the form and show a message  par = frm.parentNode;  par.removeChild(frm);  par.innerHTML = "Thank you";  return false;}</style><body>  <?$link = mysql_connect("mysql", "", "") or die ("No connection");   mysql_select_db("business") or die ("no database");   $result = mysql_query("SELECT Website,Email FROM Main");echo "<table border='1' align='center'><tr><th>Website</th><th>Email</th><th>is it i-SAFE?</th></tr>";while($row = mysql_fetch_array($result))  {		  echo "<td><a href=\"http://".$row['Website']."\" target=\"_blank\">".$row['Website']."</a></td>";   	 echo "<td>"  . $row['Email'] . "</td>";?>	 <td>  <form onsubmit="return submit_request(this);">	YES<input type="radio" name="radio_group" value="1">	NO<input type="radio" name="radio_group" value="2">	<input type="submit" value="Vote">  </form></td>		<?echo "</tr>";  }echo "</table>";?></body></html>

Thankx again,The url is still the samehttp://i-s-a-f-e.com/business/w3schools_test.php

Link to comment
Share on other sites

WOOOOOOOOOOOOOOOOOHOOOOOOOOOOOOOOOOOOI figured it out, now i just have to work on emailing the $vote and the $row['website']. itmight take me a few month but DAMN i will get it.Any help would be appreciated.. Thank you

Link to comment
Share on other sites

Any information that you need to submit should go in the form as hidden tags. A website ID or something you can use to identify the website should go in a hidden input in the form and then the Javascript function needs to read that as well and send it using AJAX when it sends the vote.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...