Jump to content

Using dropdown box to submit data


Hamish

Recommended Posts

Hi All,

This is my first attempt at using a dropdown box to submit data.

I am trying to use a dropdown box to pass an email address to an email form and then send to the recipient.

So far I have:

This returns the email addresses to a dropdown box .

<body>
<select name="txtEmailto2">
   <option>Please select a email from the list</option>

<?
include ("opendbincludeA.php");	
$query ="SELECT  P_Leader.PLemailAddress  FROM P_Leader"; 
$query = mysql_query($query);
$query_row=mysql_num_rows($query);


while ($row=mysql_fetch_array($query))
{	
	echo "<option>".$row['PLemailAddress']."</option>";
}

?>

</select>
</form>

</body>

The following is a simple email form, which sends an email to the recipient typed in text box. I have tried to use the dropdown box code above to replace the typed input text box without success. I can find no example as to what the syntax should for using the "option".

 

I am hoping someone with more experience with dropdown boxes / php will be able to help.

 

Regards

 

Hamish

<?php

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables

$mail_to=$txtEmailto2;
$mail_from=$txtEmailfrm2;
$mail_sub=$txtSub2;
$mail_mesg=$txtMsg;

//Check for success/failure of delivery 

if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from Reply-to:$txtEmailfrm2"))
echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
?>

<!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-2" />
<title>Untitled Document</title>
</head>
<body>



<form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()">
      <table width="100%"  border="0">
        <tr>
         <td width="33%" align="right" class="text">To : 
        <td width="67%"><input name="txtEmailto2" type="text" class="input" id="txtEmailto22" size="30" maxlength="100">        </tr>
        <tr>
          <td align="right" class="text">From : 
        <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100">        </tr>
        <tr>
          <td align="right" class="text">Subject : 
        <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100">        </tr>
        <tr>
          <td align="right" class="text">Message: 
          <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea>        </tr>
      <tr>
          <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true">
        
          <td><input name="Submit" type="submit" class="input" value="Send" />
          <input name="Submit2" type="reset" class="input" value="Reset" />
      </tr>         
      </table>
</form>
                
</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/
Share on other sites

Thanks  dweir for that,

I have tried what you suggested but must not have it right, the dynamic list is displaying outside the box as a list of email addresses, and as such can't be selected.

 

<?php

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables

$mail_to=$txtEmailto2;
$mail_from=$txtEmailfrm2;
$mail_sub=$txtSub2;
$mail_mesg=$txtMsg;

//Check for success/failure of delivery 

if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from Reply-to:$txtEmailfrm2"))
echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
?>

<!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-2" />
<title>Untitled Document</title>
</head>
<body>



<form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()">
      <table width="100%"  border="0">
        <tr>
         <td width="33%" align="right" class="text">To : 
        <td width="67%"><select><option value="txtEmailto2">
            <option>Please select a email from the list</option></select>
<?
include ("opendbincludeA.php");	
$query ="SELECT  P_Leader.PLemailAddress  FROM P_Leader"; 
$query = mysql_query($query);
$query_row=mysql_num_rows($query);


while ($row=mysql_fetch_array($query))
{	
	echo "<option>".$row['PLemailAddress']."</option>";
}

?>
          </select>          </tr>
        <tr>
          <td align="right" class="text">From : 
        <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100">        </tr>
        <tr>
          <td align="right" class="text">Subject : 
        <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100">        </tr>
        <tr>
          <td align="right" class="text">Message: 
          <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea>        </tr>
      <tr>
          <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true">
          <td><input name="Submit" type="submit" class="input" value="Send" />
        <input name="Submit2" type="reset" class="input" value="Reset" />      </tr>         
      </table>
</form>
                
</body>
</html>

As others said you need to have a value.

 

while ($row=mysql_fetch_array($query))

{

echo "<option>".$row['PLemailAddress']."</option>";

}

 

There is no value here. You must have something like this

 

while ($row=mysql_fetch_array($query))
{	
	echo "<option value=".$row['PLemailAddress'].">".$row['PLemailAddress']."</option>";
}

I am sorry if I appear stupid and I am just finding my way round php.

I have added the option value as suggested,

<form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()">
      <table width="100%"  border="0">
        <tr>
         <td width="33%" align="right" class="text">To : 
        <td width="67%"><select><option value="txtEmailto2">
            <option>Please select a email from the list</option></select>
<?
include ("opendbincludeA.php");	
$query ="SELECT  P_Leader.PLemailAddress  FROM P_Leader"; 
$query = mysql_query($query);
$query_row=mysql_num_rows($query);


while ($row=mysql_fetch_array($query))
{	
	echo "<option value=".$row['PLemailAddress'].">".$row['PLemailAddress']."</option>";
}


?>
          </select>          </tr>
        <tr>
          <td align="right" class="text">From : 
        <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100">        </tr>
        <tr>
          <td align="right" class="text">Subject : 
        <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100">        </tr>
        <tr>
          <td align="right" class="text">Message: 
          <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea>        </tr>
      <tr>
          <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true">
          <td><input name="Submit" type="submit" class="input" value="Send" />
        <input name="Submit2" type="reset" class="input" value="Reset" />      </tr>         
      </table>
</form>
                

but the returned query is still diplaying outside the dropdown box.

 

Hamish

Here is a mailing script i use the whole time that always works....

 

$firstname = 'persons name';
$email = 'persons email';

// Let's mail the User!
   $subject = " Enter Subject Here ";
   $message = " Enter Subject Here ";

   $femail = "From: $firstname<$email>";
   $remail = "Reply-To: $firstname<$email>";

    $headers = $femail  . "\r\n" .
    $remail . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

   mail('Your email Goes Here', $subject, $message, $headers);

This bit of code works fine

<?php

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables

$mail_to=$txtEmailto2;
$mail_from=$txtEmailfrm2;
$mail_sub=$txtSub2;
$mail_mesg=$txtMsg;

//Check for success/failure of delivery 

if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from Reply-to:$txtEmailfrm2"))
echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
?>

<!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-2" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<form action="" method="post" name="frmsendmail" id="frmsendmail" onsubmit="return ValidationForm()">
  <table width="100%"  border="0">
    <tr>
      <td width="33%" align="right" class="text">To : </td>
      <td width="67%"><input name="txtEmailto2" type="text" class="input" id="txtEmailto22" size="30" maxlength="100" />
      </td>
    </tr>
    <tr>
      <td align="right" class="text">From : </td>
      <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100" />
      </td>
    </tr>
    <tr>
      <td align="right" class="text">Subject : </td>
      <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100" />
      </td>
    </tr>
    <tr>
      <td align="right" class="text">Message: </td>
      <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea>
      </td>
    </tr>
    <tr>
      <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true" />
      </td>
      <td><input name="Submit" type="submit" class="input" value="Send" />
          <input name="Submit2" type="reset" class="input" value="Reset" />
      </td>
    </tr>
  </table>
</form>
<p> </p>
</body>
</html>

 

What I have been trying to do is replace the "txtEmailto2" ie the recipient with a drop down box populated by a query .

 

The query code also works fine and populates the dropdownbox

<form>
<select name="txtEmailto2">
   <option>Please select a email from the list</option>

<?
include ("opendbincludeA.php");	
$query ="SELECT  P_Leader.PLemailAddress  FROM P_Leader"; 
$query = mysql_query($query);
$query_row=mysql_num_rows($query);


while ($row=mysql_fetch_array($query))
{	
	echo "<option>".$row['PLemailAddress']."</option>";
}

?>

</select>
</form>

When I try and join them together it doesn't work.

 

Hamish

 

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.