Jump to content

Using "if" commands with 2 separate buttons / if statements


mat420

Recommended Posts

thanks x a million in advance people.  ok i know no php but i feel like im really close to editing this code to how i want it.

i want one send to check the text box captcha and everything else listed there

and i want send2 to check if email1 and email2 match, and if they do, then mail email1 and/or 2.

i preferably need to also have a separate one of these for send2 also:

<?php
if (isset($errors)) {
foreach ($errors as $error) {
	echo("<p>$error<p>\n");
}
}
?>

 

heres what i have otherwise, i basically just copied two php "if ___, then do ___" above eachother.

<?php
if ($_POST['send']) {
$errors = array();
if ($_POST['captcha'] != $_SESSION['captchacode']) {
	$errors[] = "You didn't enter the correct letters!";
}
if (empty($_POST['email']))  {
	$errors[] = "Please enter an e-mail address"; 
} 
else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 

$_POST['email'])) 
{ 
$errors[] = 'Please enter a valid e-mail address'; 
} 
if ($_POST['email1'] != $_POST['email2']) {
$errors[] = "The two emails do not match!";
}
if (!count($errors)) {
	// IMPORTANT: If you don't call this the 
	// user will keep getting the SAME code!
	captchaDone();
$name_field = $_POST['name']; 
$email_field = $_POST['email']; 
$message = $_POST['message'];
$phone = $_POST['phone'];
$optional = $_POST['callback'];
$cs = $_POST['cs'];
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$body = "Name: $name_field, Email: $email_field, Phone: $phone, Location: $cs, Call Them! 

$optional, Message: $message";
	mail($myaddress, 'Contact Form Submission', $body);
	// Notice we can shift in and out of "HTML mode"
	// to display some HTML only when the 
	// user passes the test
?>
<?php
if ($_POST['send2']) {
$errors = array();
if ($_POST['captcha2'] != $_SESSION['captchacode']) {
	$errors[] = "You didn't enter the correct letters!";
}
if (empty($_POST['email1']))  {
	$errors[] = "Please enter an e-mail address"; 
} 
else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 

$_POST['email1'])) 
{ 
$errors[] = 'Please enter a valid e-mail address'; 
} 
if ($_POST['email1'] != $_POST['email2']) {
$errors[] = "The two emails do not match!";
}
if (!count($errors)) {
	// IMPORTANT: If you don't call this the 
	// user will keep getting the SAME code!
	captchaDone();
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$body = "$email1, $email2";
	mail($myaddress, 'Contact Form Submission', $body);
	// Notice we can shift in and out of "HTML mode"
	// to display some HTML only when the 
	// user passes the test

?>

Link to comment
Share on other sites

else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",

$_POST['email1']))

 

 

should there be one between those 2 lines?

well send1 and send2 both are suppose to check captchas and meet other criteria before submitting.

i dont really care if the same captcha shows, so i used the same image (if thats even possible..with two different criterias needing to be met)

but i want send1, to check email entered, valid email, valid captcha on the right hand side

and then send2 on the left, i want to check email1 and email2 text boxes to make sure they match, as well as captcha

and send if so.

 

http://aciddr0p.net/drtest/demo2.php  <- ignore the "email us" button, and theres an emample. i need a new error label for the left hand side too. im trying to create a quick ...wow im an idiot.

im making a "request a call back" not request an email back. email1 and email2 need to have matching PHONE NUMBERS not emails. not that it makes a difference. thank you.

Link to comment
Share on other sites

Ahhh now this makes sense lol.

 

What I would do is pretty similar to what you have.. Give each submit button a different name, then when processing in php:

//assuming left send button is called submitEmail and right is called submitContact
if(isset($_POST["submitEmail"])){
  //do the form processing for the email submission part
}else if(isset($_POST["submitContact"])){ 
  //do the form processing for the contact part
}

 

Is that the sort of thing you're after?

 

Denno

Link to comment
Share on other sites

well look, this is the working code, to check the form on the right. and send if everythings good.

<?php
if ($_POST['send']) {
$errors = array();
if ($_POST['captcha'] != $_SESSION['captchacode']) {
	$errors[] = "You didn't enter the correct letters!";
}
if (empty($_POST['email']))  {
	$errors[] = "Please enter an e-mail address"; 
} 
else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) 
{ 
$errors[] = 'Please enter a valid e-mail address'; 
} 
if ($_POST['email1'] != $_POST['email2']) {
$errors[] = "The two emails do not match!";
}
if (!count($errors)) {
	// IMPORTANT: If you don't call this the 
	// user will keep getting the SAME code!
	captchaDone();
$name_field = $_POST['name']; 
$email_field = $_POST['email']; 
$message = $_POST['message'];
$phone = $_POST['phone'];
$optional = $_POST['callback'];
$cs = $_POST['cs'];
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$body = "Name: $name_field, Email: $email_field, Phone: $phone, Location: $cs, Call Them! $optional, Message: $message";
	mail($myaddress, 'Contact Form Submission', $body);
	// Notice we can shift in and out of "HTML mode"
	// to display some HTML only when the 
	// user passes the test
?>

 

 

i need to know how to add if commands for ANOTHER button now, it didnt let me just put it right underneith (send2).

 

Link to comment
Share on other sites

my code looks good then? all i did was take the code i showed u right in the last post

and i added this immediately underneath it:

 

<?php
if ($_POST['send2']) {
$errors = array();
if ($_POST['captcha2'] != $_SESSION['captchacode']) {
	$errors[] = "You didn't enter the correct letters!";
}
if (empty($_POST['email1']))  {
	$errors[] = "Please enter an e-mail address"; 
} 
else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 

$_POST['email1'])) 
{ 
$errors[] = 'Please enter a valid e-mail address'; 
} 
if ($_POST['email1'] != $_POST['email2']) {
$errors[] = "The two emails do not match!";
}
if (!count($errors)) {
	// IMPORTANT: If you don't call this the 
	// user will keep getting the SAME code!
	captchaDone();
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$body = "$email1, $email2";
	mail($myaddress, 'Contact Form Submission', $body);
	// Notice we can shift in and out of "HTML mode"
	// to display some HTML only when the 
	// user passes the test
?>

Link to comment
Share on other sites

It needs to be an else if mate. The user can't hit both the submit buttons at the same time? So you're checking one OR the other, not both...

 

Also, on your site, you don't have any form tags for the email part, only in the contact part.. I assume you will be fixing this up?

 

Denno

Link to comment
Share on other sites

i dont follow. what exactly is wrong? what needs to be self if exactly? when i had the 2nd to last code posted, it worked fine on that contact form. i made "name" and "email" have to match before it sent (just as a test), but when i tried to make that a requirement on the left hand side, on 2 new text boxes, it didnt work.

 

then if it helps any i got this thats USING that php - sorruy for the mess

<input type="text" name="email1" id="email1" MAXLENGTH=30 value="<?php if  

(!empty($_POST['email1'])) { echo $_POST['email1']; } ?>" />
<input type="text" name="email2" id="email2" MAXLENGTH=30 value="<?php if  

(!empty($_POST['email2'])) { echo $_POST['email2']; } ?>" />
</p>
              
<td valign="top"><input name="captcha2" size="8"/>
</td> 
</tr><tr>
<td valign="top"><span class="class2">
  <label for="Message"><a href="<?php echo captchaWavUrl()?>">Listen To This</a> / <a 

href="javascript:location.reload(true);">Refresh</a></label></span>
</td>
</tr>
<tr>
<img style="vertical-align: middle" src="<?php echo captchaImgUrl()?>">  

  <input type="submit" name="send2" value="Submit"/>
<font color="red"><b><?php
if (isset($errors)) {
foreach ($errors as $error) {
	echo("<p>$error<p>\n");
}
}
?>

Link to comment
Share on other sites

i dont follow. if send1 is hit it checks one thing (actually 2-3) and if send2 is hit, it checks email1 and email2

i can make it do that i think. i just needd to know hoq to setup the 2 different scenarios if i cant just put them right above/under eachother

Link to comment
Share on other sites

Yeah man that's what I'm trying to tell you... From the code that I posted, only one if section will run, so it doesn't matter if you have similar or the same code in the top 'if' as you do in the 'else if' because only one will run.

 

Follow the format that I gave you, and you shouldn't have any problems..

 

Denno

Link to comment
Share on other sites

Dude seriously... Here is the code again, read the comments in the code (they'll appear orange)

//assuming left send button is called submitEmail and right is called submitContact
if(isset($_POST["submitEmail"])){
  //do the form processing for the email submission part
}else if(isset($_POST["submitContact"])){ 
  //do the form processing for the contact part
}

 

I can't help you any further if you can't understand what I'm suggesting to you here..

 

Denno

Link to comment
Share on other sites

i just wanna make sure were on the same page at least, u see that this part is my error right? as soon as i put this "if send button is hit" under the under "if send button is hit" the page stops loading

Parse error: syntax error, unexpected $end in /homepages/4/d289686807/htdocs/drtest/demo2.php on line 735

 

thanks man

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.