开发者

How do you stop a php page from reloading and reloading its attributes?

开发者 https://www.devze.com 2023-04-11 00:50 出处:网络
Hi I\'m trying to migrate my HTML/PHP/JS/XML page into one php file. I was able to successfully make my application using the 4 files seperately but when i put them into one it seems my js and php are

Hi I'm trying to migrate my HTML/PHP/JS/XML page into one php file. I was able to successfully make my application using the 4 files seperately but when i put them into one it seems my js and php are in conflict, also if there is a way i can make radio buttons set to no options by default, because I'm guessing that's where the problem lies.

Hmm i already solved the problem regarding the radio buttons, anyway I'm trying to have them all on one page because I'm trying to mimic the output of a local program, i realized this one when i saw the output of my first attempt. so what I'm trying to do right now is after running the php code i want to put them in a div so they won't fly all over the place. I already solved this part but my problem right now is when i select the next radio button in my options, the result of previous request is still there unless I click on my submit button. I'm guessing that it has something to do with the js I passed on the body of my html. attempting to fix the div issue in js however was ok but it only showed the div for a split second.

Here is my code:

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Globe2Smac</title>
  <link rel="stylesheet" href="css/mycss.css" type="text/css">
  <script src="js/hide.js" type="text/javascript"></script>
  </head>
  <body onLoad="">
  <h2>Globe to SMAC Function</h2>
          <form method="post" action="">
          <div>
          <ul style="list-style:none">
              <li><input id="smember" type ="开发者_C百科radio" name ="option" value = "SmacMembers" onChange="SMmember()" checked/>SMAC MEMBERS</li>
              <li><input  id="sbalance"type ="radio" name ="option" value = "SmacBalance" onChange="SMbalance()" checked/>SMAC BALANCE QUERY</li>
              <li><input id="saward" type ="radio" name ="option" value = "SmacAward" onChange="SMaward()" checked/>SMAC AWARD</li>
              <li><input id="sredemption" type ="radio" name ="option" value = "SmacRedeem" onChange="SMredeem()" checked/>SMAC REDEMPTION</li>
          </ul>
              <div>Globe XML RPC Request:</div>
              <div id="smmember" class="div-border" style="display:none"><textarea id="areamember" name="gmember" value="Member" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.members</methodName>
<params>
<param>
<value>
<string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_members&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;12345678&amp;lt;/transaction_id&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
              <div id="smbalancequery"class="div-border" style="display:none"><textarea id="areabalance" name="gbalance" value="Balance" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.balance_query</methodName>
<params>
<param><value><string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_balance_query&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt;
&amp;lt;birthday&amp;gt;01011900&amp;lt;/birthday&amp;gt;   
&amp;lt;transactiondatetime&amp;gt;2011-09-16 13:43:58&amp;lt;/transactiondatetime&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string></value></param>
</params>
</methodCall>
</textarea></div>
              <div id="smaward" class="div-border"style="display:none"><textarea id="areaward" name="gaward" value="Award" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.award_points</methodName>
<params>
<param>
<value>
<string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_award_points&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt;
&amp;lt;transaction_amount&amp;gt;100&amp;lt;/transaction_amount&amp;gt;
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt;
&amp;lt;transactiondatetime&amp;gt;2011-09-22 16:20:58&amp;lt;/transactiondatetime&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
              <div id="smredemption" class="div-border"style="display:none"><textarea id="arearedeem" name="gredeem" value="Redeem" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.redemption_points</methodName>
<params>
<param>
<value>
<string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_redemption_points&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt;
&amp;lt;transaction_amount&amp;gt;10&amp;lt;/transaction_amount&amp;gt;
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt;
&amp;lt;transactiondatetime&amp;gt;20110921 16:20:58&amp;lt;/transactiondatetime&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="submit"><input type="submit" name="Submit" value="Submit Query"></div>
<div>Globe XML Response:</div>
<div class="div-border"><?php
  if($_POST['option'] == "SmacMembers"){
  $member = $_POST['gmember'];
  $URL = 'https://localhost/globe2smac-fh3/api/';
  $ch = curl_init($URL);
  //curl_setopt($ch, CURLOPT_URL, "https://localhost/globe2smac-fh3/api");
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/html'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, $member);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2);
  $MemResult = curl_exec($ch);
  curl_close($ch);
  }
  else if($_POST['option'] == "SmacBalance"){
  $balance= $_POST['gbalance'];
  echo $balance; 
  $URL = "https://localhost/globe2smac-fh3/api/";

  $ch = curl_init($URL);
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$balance");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $BalResult= curl_exec($ch);
  curl_close($ch);

  echo $output;

  }
  else if($_POST['option'] == "SmacAward"){
  $award=$_POST['gaward'];
  echo $award;
  $URL = "https://localhost/globe2smac-fh3/api/";

  $ch = curl_init($URL);
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$award");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($ch);
  curl_close($ch);

  echo $output;
  }
  else if($_POST['option'] == "SmacRedeem"){
  $redeem=$_POST['gredeem'];
  echo $redeem;
  $URL = "https://localhost/globe2smac-fh3/api/";

  $ch = curl_init($URL);
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$redeem");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $RedResult = curl_exec($ch);
  curl_close($ch);

  echo $output;
  }
  else{
  echo('Option not Found');
}
?></div>
              </div>
            </form>
      </body>
  </html>

re-updated my code to this:

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Globe2Smac</title>
  <link rel="stylesheet" href="css/mycss.css" type="text/css">
  <script src="js/hide.js" type="text/javascript"></script>
  </head>
  <body onLoad="siteLoad();">
  <h2>Globe to SMAC Function</h2>
          <form method="post" action="">
          <div>
          <ul style="list-style:none">
              <li><input id="smember" type ="radio" name ="option" value = "SmacMembers" onChange="SMmember()" />SMAC MEMBERS</li>
              <li><input  id="sbalance"type ="radio" name ="option" value = "SmacBalance" onChange="SMbalance()"/>SMAC BALANCE QUERY</li>
              <li><input id="saward" type ="radio" name ="option" value = "SmacAward" onChange="SMaward()"/>SMAC AWARD</li>
              <li><input id="sredemption" type ="radio" name ="option" value = "SmacRedeem" onChange="SMredeem()"/>SMAC REDEMPTION</li>
          </ul>
              <div>Globe XML RPC Request:</div>
              <div id="smmember" class="div-border" style="display:none"><textarea id="areamember" name="gmember" value="Member" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.members</methodName>
<params>
<param>
<value>
<string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_members&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;12345678&amp;lt;/transaction_id&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
              <div id="smbalancequery"class="div-border" style="display:none"><textarea id="areabalance" name="gbalance" value="Balance" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.balance_query</methodName>
<params>
<param><value><string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_balance_query&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521960565&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt;
&amp;lt;birthday&amp;gt;01011900&amp;lt;/birthday&amp;gt;   
&amp;lt;transactiondatetime&amp;gt;2011-09-16 13:43:58&amp;lt;/transactiondatetime&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string></value></param>
</params>
</methodCall>
</textarea></div>
              <div id="smaward" class="div-border"style="display:none"><textarea id="areaward" name="gaward" value="Award" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.award_points</methodName>
<params>
<param>
<value>
<string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_award_points&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt;
&amp;lt;transaction_amount&amp;gt;100&amp;lt;/transaction_amount&amp;gt;
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt;
&amp;lt;transactiondatetime&amp;gt;2011-09-22 16:20:58&amp;lt;/transactiondatetime&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
              <div id="smredemption" class="div-border"style="display:none"><textarea id="arearedeem" name="gredeem" value="Redeem" spellcheck="false">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodCall>
<methodName>smac.redemption_points</methodName>
<params>
<param>
<value>
<string>
&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;globetosmac&amp;gt;
&amp;lt;functioncode&amp;gt;smac_redemption_points&amp;lt;/functioncode&amp;gt;
&amp;lt;cardnumber&amp;gt;8880999521060440&amp;lt;/cardnumber&amp;gt;
&amp;lt;transaction_id&amp;gt;1441795&amp;lt;/transaction_id&amp;gt;
&amp;lt;transaction_amount&amp;gt;10&amp;lt;/transaction_amount&amp;gt;
&amp;lt;transaction_code&amp;gt;OFLN-GLOBE&amp;lt;/transaction_code&amp;gt;
&amp;lt;transactiondatetime&amp;gt;20110921 16:20:58&amp;lt;/transactiondatetime&amp;gt;
&amp;lt;/globetosmac&amp;gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="submit"><input type="submit" name="Submit" value="Submit XML Request"></div>
<div>Globe XML Response:</div>
<div class="div-border"><?php
  if($_POST['option'] == "SmacMembers"){
  $member = $_POST['gmember'];
  $URL = 'https://localhost/globe2smac-fh3/api/';
  $ch = curl_init($URL);
  //curl_setopt($ch, CURLOPT_URL, "https://localhost/globe2smac-fh3/api");
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/html'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, $member);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2);
  $MemResult = curl_exec($ch);
  curl_close($ch);
  echo $MemResult;
  }
  else if($_POST['option'] == "SmacBalance"){
  $balance= $_POST['gbalance'];
  $URL = "https://localhost/globe2smac-fh3/api/";

  $ch = curl_init($URL);
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$balance");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $BalResult= curl_exec($ch);
  curl_close($ch);
  echo $BalResult;

  }
  else if($_POST['option'] == "SmacAward"){
  $award=$_POST['gaward'];
  echo $award;
  $URL = "https://localhost/globe2smac-fh3/api/";

  $ch = curl_init($URL);
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$award");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $Awresult= curl_exec($ch);
  curl_close($ch);

  echo $Awresult;
  }
  else if($_POST['option'] == "SmacRedeem"){
  $redeem=$_POST['gredeem'];
  echo $redeem;
  $URL = "https://localhost/globe2smac-fh3/api/";

  $ch = curl_init($URL);
  curl_setopt($ch, CURLOPT_MUTE, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$redeem");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $RedResult = curl_exec($ch);
  curl_close($ch);

  echo $RedResult;
  }
  else{
  echo('Processing Requests...');
}
?></div>
              </div>
            </form>
      </body>
  </html>


Well right now you have set all of your radio buttons to checked;

<input type="radio" ... checked />

First of all the right syntax is:

<input type="radio" ... checked="checked" />

Furthermore be sure only ONE radio button is checked (it's in the nature of the radio button :)) or use checkboxes

Just a question; why would you want to merge everything into one file? for maintainability most of the times separating your code is a pretty good idea!

0

精彩评论

暂无评论...
验证码 换一张
取 消