PHP form field won't submit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jman408
Forum Newbie
Posts: 1
Joined: Sat Mar 03, 2007 1:15 am

PHP form field won't submit

Post by jman408 »

The Ninja Space Goat | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I’m an html guy and I’m trying to add onto someone else’s php coding – and I can’t figure it out.

Basically, I want to add multiple fields to the form, but how do I code that on the php script side? I tried to just copy and paste the code, and rename some of the variables, but that doesn’t work. I've been pulling my hair out, and I know it's something simple, but I just can't get it.

Any help would be most appreciated. 

Thank you so much

Here is the script:
---------------------------------------------------------------------------------------

Code: Select all

<?php
	$Que=array();
	$Que[0]="Do you know the demand curve and price elasticity of your main products?";
	$Que[1]="Do you often create bundles and special editions of your products for particular market segments?";
	$Que[2]="Have you identified distinct market segments, and do you serve these market segments, products, and services at different price points?";
	$Que[3]="Do you know what attributes of your products and services drive buying decisions and control their willingness to pay?";
	
			
	if($_REQUEST['btnSubmit']=='Submit')
	 {
	 	$Ans=array();
		$Email=$_REQUEST['txtEmail'];
		$Message .="<table width=100%  cellpadding=3 style=' font-family:verdana; font-size:10px;' >
		<tr ><td colspan=2><b><Font face=verdana size=3>Price Quiz</span></b><br><br></td></tr>
		<tr ><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;Sender's Email Address: <b>$Email </b><br><br></td></tr>";
	    for($i=0,$c=1;$i<count($Que);$i++,$c++)
		 {
		 $Nm="rdb".$i;
		 
			  if($_REQUEST[$Nm]==0) {  $Ans[$i]="Yes";  }else{ 	$Ans[$i]="No"; }
			$Message .="<tr><td width=10></td><td ><b>$c. </b>&nbsp;".$Que[$i]."<br><b>A:</b>&nbsp;".$Ans[$i]."</td></tr><tr><td>&nbsp;</td></tr>";	  
		  }	  
					
		$Message .="</table>";
//--------------address of receiver---------------		
		$To="jchristofferson@hotmail.com";		
		
		$From=$Email;
		$headers.="MIME-Version:1.0"."\r\n";
		$headers.="content-type:text/html; charset=iso-8859-1"."\r\n";
		$headers.="TO:$To"."\r\n";	$headers.="From:$Email"."\r\n";
		$Sub="Price Quiz ";
		
		if(@mail($To,$Sub,$Message,$headers))
		 {
		 	$Msg="Mail has been sent successfully";
			$_REQUEST['txtEmail']="";
		 }
		else $Msg="Sorry, the email could not be sent!";   
				
	 }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>Pricing Strategy - Atenga, Inc - Price Quiz</TITLE>
<META NAME="description" CONTENT="Move beyond strategic price consulting with our experience in marketing, perception analysis, financials, statistics, and general business management. Increase ROI with our price recommendation.">
<META NAME="keywords" CONTENT="marketing, perception analysis, financials, pricing strategy, statistics, business management, price recommendation, ROI, price consulting, executive management, price optimization, pricing strategies">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<link href="Images/main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.red {color:#FF0000; font-size:11px; font-family:Verdana, Arial, Helvetica, sans-serif; }
-->
</style>
<script type="text/javascript" language="javascript1.1">
function validateBlank(obj, msg)
{
	var string=obj.value;
	
	if(string.length<=0)
	{
		alert(msg);
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}

function validateEmail(obj, msg)
{
	var emailStr = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	if (emailStr.test(obj.value) == false)
	{
		alert(msg);
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}
</script>
<script type="text/javascript" language="javascript1.1">


function validation()
{    //alert(document.frmReg.txtFNm.value);
			
	if(validateBlank(document.frmQue.txtEmail , "Enter Email ")==false) 				return false;
	if(validateEmail(document.frmQue.txtEmail, "Enter valid Email ") == false)
			return false;
}	
</script>
</head>

<body>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td c><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="180" height="122" valign="bottom"><a href="index.htm"><img src="Images/logo.gif" width="180" height="52" border="0" /></a></td>
                    <td width="595" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td height="3" bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                          <td bgcolor="#F68E0F"></td>
                        </tr>
                        <tr>
                          <td width="67" height="23" align="center" bgcolor="#7E91A2"><a href="services.php"><img src="Images/link1.gif" width="49" height="10" border="0" /></a></td>
                          <td width="1" align="center" bgcolor="#7E91A2"><img src="Images/link_bg.jpg" width="1" height="10" /></td>
                          <td width="83" align="center" bgcolor="#7E91A2"><a href="register.php"><img src="Images/link3.gif" width="60" height="10" border="0" /></a></td>
                          <td width="1" align="center" bgcolor="#7E91A2"><img src="Images/link_bg.jpg" width="1" height="10" /></td>
                          <td width="47" align="center" bgcolor="#7E91A2"><a href="faq.php"><img src="Images/link4.gif" width="23" height="11" border="0" /></a></td>
                          <td width="1" align="center" bgcolor="#7E91A2"><img src="Images/link_bg.jpg" width="1" height="10" /></td>
                          <td width="89" align="center" bgcolor="#7E91A2"><a href="affiliation.htm"><img src="Images/link5.gif" width="62" height="10" border="0" /></a></td>
                          <td width="1" align="center" bgcolor="#7E91A2"><img src="Images/link_bg.jpg" width="1" height="10" /></td>
                          <td width="76" align="center" bgcolor="#7E91A2"><a href="contact.htm"><img src="Images/link6.gif" width="44" height="10" border="0" /></a></td>
                          <td width="1" align="center" bgcolor="#7E91A2"><img src="Images/link_bg.jpg" width="1" height="10" /></td>
                          <td width="77" align="center" bgcolor="#7E91A2"><a href="aboutus.htm"><img src="Images/link7.gif" width="52" height="13" border="0" /></a></td>
                        </tr>
                        <tr>
                          <td height="1"></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td></td>
                        </tr>
                    </table></td>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="420"><img src="Images/priceq_img1.jpg" width="420" height="131" /></td>
                    <td width="355"><img src="Images/priceq_img2.jpg" width="355" height="131" /></td>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <td height="7" bgcolor="#ED850C"></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td height="10" valign="top">
		
		<table width="775" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="40" align="center">&nbsp;</td>
          </tr>
          
          <tr>
            <td height="30" align="right" valign="top">
			<form name="frmQue" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" >
			<table width="750" border="0" align="right" cellpadding="0" cellspacing="0">
			
<?php 	if(strlen($Msg)>0){?>
           <tr>
                <td  colspan="3" height="25" valign="middle" class="red" align="left"><?php echo $Msg;?></td></tr>
<?php }?>				
 <?php for ($j=0,$c1=1;$j<count($Que);$j++){?>
			  
			  <tr>
                <td width="24" align="left"><img src="Images/faq-arrow.jpg" width="12" height="11" /></td>
                <td width="705" align="left" class="arial1_11_grey"><?php echo $Que[$j];?></td>
                <td width="21" align="left">&nbsp;</td>
              </tr>
              <tr>
                <td height="20" align="left">&nbsp;</td>
                <td align="left" class="arial1_11_grey">Answer:</td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr>
                <td align="left">&nbsp;</td>
                <td align="left"><table width="100" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="15"><input type="radio" name="rdb<?php echo $j;?>" value="0" checked="checked"></td>
                    <td width="45" align="center" class="arial1_11_grey">Yes</td>
                    <td width="15"><input type="radio" name="rdb<?php echo $j;?>" value="1"></td>
                    <td width="45" align="center" class="arial1_11_grey">No</td>
                  </tr>
                </table></td>
				
                <td align="left">&nbsp;</td>
              </tr>
              <tr>
                <td align="left">&nbsp;</td>
                <td align="left">&nbsp;</td>
                <td align="left">&nbsp;</td>
              </tr>
			  
<?php }?>	  
              <tr>
                <td align="left">&nbsp;</td>
                <td align="left" valign="top"><table width="350" border="0" cellpadding="0" cellspacing="0" bgcolor="#F6F6F6">
                  <tr>
                    <td width="72">&nbsp;</td>
                    <td width="161">&nbsp;</td>
                    <td width="117">&nbsp;</td>
                  </tr>
                 <tr>
                    <td align="left" class="tahoma-11-blue_bold"><span class="red">* </span><span class="arial_11_grey_bold_">Name :</span></td>
                    <td align="left"><input type="text" maxlength="100" name="txtName" value="" class="text_box" /></td>
                  </tr>
                  <tr>
                    <td align="left" class="tahoma-11-blue_bold"><span class="red">* </span><span class="arial_11_grey_bold_">Company :</span></td>
                    <td align="left"><input type="text" maxlength="100" name="txtCompany" value="" class="text_box" /></td>
                  </tr>
                  <tr>
                    <td align="left" class="tahoma-11-blue_bold"><span class="red">* </span><span class="arial_11_grey_bold_">Email :</span></td>
                    <td align="left"><input type="text" maxlength="100" name="txtEmail" value="" class="text_box" /></td>
                  </tr>
                  <tr>
                    <td align="left" class="tahoma-11-blue_bold"><span class="red">* </span><span class="arial_11_grey_bold_">Tel :</span></td>
                    <td align="left"><input type="text" maxlength="100" name="txtTel" value="" class="text_box" /></td>
                  </tr>
                  <tr>
                    <td align="left" class="tahoma-11-blue_bold"><span class="red">* </span><span class="arial_11_grey_bold_">Comments :</span></td>
                    <td align="left"><textarea rows="2" cols="22" name="" id=""></textarea></td>
                    <td align="left"><input type="image" src="Images/submit1.jpg" width="61" height="21" onclick="return validation();" />
					<input type="hidden" name="btnSubmit" value="Submit" /></td>
                  </tr>
                  <tr>
                    <td height="10"></td>
                    <td></td>
                    <td></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td colspan="2" valign="top" class="arial1_11_grey">We will email the response back to the email address</td>
                    </tr>
                  <tr>
                    <td height="10"></td>
                    <td></td>
                    <td></td>
                  </tr>
                </table>                  
                  </td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr>
                <td align="left">&nbsp;</td>
                <td align="left">&nbsp;</td>
                <td align="left">&nbsp;</td>
              </tr>
          
              
            </table>
			</form>
			</td>
          </tr>
          
          <tr>
            <td height="30">&nbsp;</td>
          </tr>
          

        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td valign="top" style="border-top:#BABABA solid 3px"><table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td height="30" align="center" class="arial1_11_grey"><table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <tr>
            <td width="570" height="30" align="right" class="arial1_11_grey">Copyright 2006 @ Atenga, Inc.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td width="205" align="right" class="arial-11-blue1"><a href="term-of-use.htm" class="arial-11-blue1">Terms of use and Privacy Policy</a></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

The Ninja Space Goat | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

It looks like the old code took the email field only. Is that right?

First suggestion would be to get out of the habit of using the $_REQUEST superglobal. You know the data is being sent from a form using the POST method, so use the $_POST superglobal. The next thing you will have to do is gather the form data from the $_POST array, so as an example, where there is a form field in the markup called txtEmail, there should be a corresponding assignment in the PHP that sets a var from $_POST['txtEmail']. That variable will then hold the data that was sent in the form.

Keep in mind that there are a lot of things to watch out for when taking user supplied data, like SQL injection, XSS and others.
Post Reply