Jump to content

Placing value from an operation into form/email


j1bird2k

Recommended Posts

I have an online quiz that generates a results page in html.  I want to be able to email the results from the page using POST in php. I have the form working, I just can't get the value from the Grade Percent Score box to post in the php formmail. My work around is to ask the user to put the score in when they file in their name and email. Not the best in this grade inflating environment in education...

 

<html>

 

<head>

<title>Chapter One Quiz Results</title>

</head>

 

<body bgcolor="#FFFFFF">

 

<p align="center"><strong><font face="Arial">

 

<script src="quizconfig.js">

</script>

 

<big>Chapter One Healthy Lifestyles Quiz Results<br>

*Required Fields </big></font></strong></p>

<div align="center"><center>

  <tr>

  <td width="100%">

 

<form method="POST" name="result"><table border="0" width="100%" cellpadding="0" height="116">

        <tr>

          <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial"># of questions you got right:</font></strong></td>

          <td height="25"><p><input type="text" name="p" size="24"></td>

        </tr>

        <tr>

          <td height="17" bgcolor="#D3FFA8"><strong><font face="Arial">The questions you got wrong:</font></strong></td>

          <td height="17"><p><textarea name="T2" rows="3" cols="24" wrap="virtual"></textarea></td>

        </tr>

        <tr>

          <td height="25" bgcolor="#D3FFA8"><strong><font face="Arial">Grade in percentage:</font></strong></td>

          <td height="25"><input type="text" name="q" size="8">

          Box "G" </td>

        </tr>

      </table>

    </form>

    </td>

  </tr>

 

<form method="POST" action="http://www.corehealthco.com/formmail.php" name="SampleForm">

            <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER">

 

            <input type="hidden" name="recipients" value="[email protected]" />

            <!-- STEP 3: Specify required fields in the 'required' value -->

            <input type="hidden" name="required" value="q:Test Result,email:Your email address,realname:Your name" />

 

            <input type="hidden" name="subject" value="C1 Quiz Results" />

            *Enter your grade percentage to match Box "G"

<input type="text" name="q" size="8" />

            <p>*Your Name:

              <input type="text" name="realname">

            </p>

            *Please enter your email address:

            <input type="text" name="email" />

            <table border="0" cellspacing="0" cellpadding="0">

</center></div>

 

<form method="POST">

  <div

  align="center"><center><p>

 

<script>

var wrong=0

for (e=0;e<=2;e++)

document.result[e].value=""

 

var results=document.cookie.split(";")

for (n=0;n<=results.length-1;n++){

if (results[n].charAt(1)=='q')

parse=n

 

}

 

var incorrect=results[parse].split("=")

incorrect=incorrect[1].split("/")

if (incorrect[incorrect.length-1]=='b')

incorrect=""

document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions

document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%"

for (temp=0;temp<incorrect.length;temp++)

document.result[1].value+=incorrect[temp]+", "

 

 

</script>

<input type="button" value="View solution" name="B2"

  onClick="showsolution()">

<input name="submit" type="submit" value="Submit" />

  </p>

  </center></div>

</form>

 

</body>

</html>

 

Hi,

It looks like you opened a second form tag in the page and could be conflicting with the main form. The best way I can think of to work with post is storing the score into a hidden field and name it something basic like "score", then on the formmail.php file you'll have to add in the variable

 

$score = $_POST['score'];

 

Then you'll have to have that send as part of the email's body, that's as long as everything else is already working the way it should and you want to just add in the one extra part of the results. I hope that helps!

 

-Frank

I have fields available in my formmail.php that I could assign the "score" The challenge I have is that the score is generated in this js function:

 

function gradeit(){

var incorrect=null

for (q=1;q<=totalquestions;q++){

var thequestion=eval("document.myquiz.question"+q)

for (c=0;c<thequestion.length;c++){

if (thequestion[c].checked==true)

actualchoices[q]=thequestion[c].value

}

 

if (actualchoices[q]!=correctchoices[q]){ //process an incorrect choice

if (incorrect==null)

incorrect=q

else

incorrect+="/"+q

}

}

 

if (incorrect==null)

incorrect="a/b"

document.cookie='q='+incorrect

if (document.cookie=='')

alert("Your browser does not accept cookies. Please adjust your browser settings.")

else

window.location="results.htm"

}

 

That's how it gets to the resutls page.  Wouldn't I need to tell it to put it in the "score" field from this operation?  Then in the second "post" on the results page, which is working fine, include the value in the email as part of the operations in formmail.php? 

 

How would I do that? or is there another way?

thanks,

j

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.