Jump to content

[SOLVED] Autofill a form element by clicking on a link?


madhattan

Recommended Posts

That is the subject.

 

$EmailFrom = "contact@depaulaclark.com";
$Subject = "D & C Contact Form Submission";
$Name = Trim(stripslashes($_POST['Name'])); 
$Company = Trim(stripslashes($_POST['Company'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

Link to comment
Share on other sites

The output you supplied is incorrect then

have you tried echoing the value ?

 

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
var_dump($success);
die("$EmailTo,\n$Subject,\n$Body,\nFrom: <$EmailFrom>");

 

I added the above code, then tried to submit and got the following...

 

bool(false) , D & C Contact Form Submission, Name: ghghgh Company: ghghghgh Email: ghghgh@ghghg.com Message: ghghghgh... , From:

Link to comment
Share on other sites

that is the output. Maybe the $EmailTo part is wrong so its not echoing?

 

Would it have to do with making the URLs the following:

 

<li><a href="http://www.depaulaclark.com/contact.php?name=1">Cynthia DePaula</a></li>
    		<li><a href="http://www.depaulaclark.com/contact.php?name=2">Lily Clark</a></li>
    		<li><a href="http://www.depaulaclark.com/contact.php?name=3">Gina Lasko</a></li>
    		<li><a href="http://www.depaulaclark.com/contact.php?name=4">Sarwar Chowdhury</a></li>
    		<li><a href="http://www.depaulaclark.com/contact.php?name=5">Nathan Sherwoon</a></li>
            <li><a href="http://www.depaulaclark.com/contact.php?name=6">Jay Rahman</a></li>
    		<li><a href="http://www.depaulaclark.com/contact.php?name=7">Tommy Allen</a></li>

 

And then switching like this?

 

switch($_GET['name'])
{
case '1':
$EmailTo = 'cynthia@depaulaclark.com';
break;

case '2':
$EmailTo = 'lily@depaulaclark.com';
break;

case '3':
$EmailTo = 'gina@depaulaclark.com';
break;

case '4':
$EmailTo = 'sarwar@depaulaclark.com';
break;

case '5':
$EmailTo = 'nathan@depaulaclark.com';
break;

case '6':
$EmailTo = 'jay@depaulaclark.com';
break;

case '7':
$EmailTo = 'tommy@depaulaclark.com';
break;

default:
$EmailTo = $_GET['name'];
}

Link to comment
Share on other sites

i see. Well, i think i have narrowed it down to when the link URLs and the default $emailto were changed, because it was working fine before this...

 

default:
$EmailTo = $_GET['name'];

 

<li><a href="http://www.depaulaclark.com/contact.php?name=1">Cynthia DePaula</a></li>

 

any ideas?

Link to comment
Share on other sites

Here is the full form.

 

<form method="post" action="contactengine.php">
			<table>
				<tr>
					<td class="left"><label for="Name">Name:</label></td>
					<td><input type="text" name="Name" /></td>
				</tr>
				<tr>
					<td class="left"><label for="Company">Company:</label></td>
					<td><input type="text" name="Company" /></td>
				</tr>
				<tr>
					<td class="left"><label for="Email">Email:</label></td>
					<td><input type="text" name="Email" /></td>
				</tr>
                    <tr>
                    	<td class="left"><label for="To">To:</label></td>
                        <td><select name='emailto' id='emailto' value="<?php echo "name"; ?>" />
							<option value="1"<?php echo ($_GET['name'] == 1) ? "Selected='selected'" : ""; ?>>Cynthia DePaula</option>
							<option value="2"<?php echo ($_GET['name'] == 2) ? "Selected='selected'" : ""; ?>>Lily Clark</option>
							<option value="3"<?php echo ($_GET['name'] == 3) ? "Selected='selected'" : ""; ?>>Gina Lasko</option>
                                <option value="4"<?php echo ($_GET['name'] == 4) ? "Selected='selected'" : ""; ?>>Sarwar Chowdury</option>
                                <option value="5"<?php echo ($_GET['name'] == 5) ? "Selected='selected'" : ""; ?>>Nathan Sherwood</option>
                                <option value="6"<?php echo ($_GET['name'] == 6) ? "Selected='selected'" : ""; ?>>Jay Rahman</option>
                                <option value="7"<?php echo ($_GET['name'] == 7) ? "Selected='selected'" : ""; ?>>Tommy Allen</option>
						</select></td>
                    </tr>
				<tr>
					<td class="left"><label for="Message">Message:</label></td>
					<td><textarea name="Message" rows="20" cols="20"></textarea></td>
				</tr>
			</table>

<div id="captcha-area">
			<?php
			require_once('recaptchalib.php');
			$publickey = "6LcqrwcAAAAAAD1UeuZI584GhZBvyE0vYVwDN2-N";
			$privatekey = "6LcqrwcAAAAAANr7jMoEZ56UajiN08yZ4ouOCUKV";

			# the response from reCAPTCHA
			$resp = null;
			# the error code from reCAPTCHA, if any
			$error = null;

			# are we submitting the page?
			if ($_POST["submit"]) {
			  $resp = recaptcha_check_answer ($privatekey,
											  $_SERVER["REMOTE_ADDR"],
											  $_POST["recaptcha_challenge_field"],
											  $_POST["recaptcha_response_field"]);

			  if ($resp->is_valid) {
				echo "You got it!";
				# in a real application, you should send an email, create an account, etc
			  } else {
				# set the error code so that we can display it. You could also use
				# die ("reCAPTCHA failed"), but using the error message is
				# more user friendly
				$error = $resp->error;
			  }
			}
			echo recaptcha_get_html($publickey, $error);
			?>

</div>

			<input type="submit" name="submit" value="Submit" class="submit-button" />
		</form>

 

And here is the contact engine.

 

<?php

require_once('recaptchalib.php');
$privatekey = "6LcqrwcAAAAAANr7jMoEZ56UajiN08yZ4ouOCUKV";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}

switch($_POST['name'])
{
case '1':
$EmailTo = 'cynthia@depaulaclark.com';
break;

case '2':
$EmailTo = 'lily@depaulaclark.com';
break;

case '3':
$EmailTo = 'gina@depaulaclark.com';
break;

case '4':
$EmailTo = 'sarwar@depaulaclark.com';
break;

case '5':
$EmailTo = 'nathan@depaulaclark.com';
break;

case '6':
$EmailTo = 'jay@depaulaclark.com';
break;

case '7':
$EmailTo = 'tommy@depaulaclark.com';
break;

default:
$EmailTo = $_GET['name'];
}

$EmailFrom = "contact@depaulaclark.com";
$Subject = "D & C Contact Form Submission";
$Name = Trim(stripslashes($_POST['Name'])); 
$Company = Trim(stripslashes($_POST['Company'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error2.htm\">";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.