Jump to content

2 separate if/else statements with their OWN error label.


mat420

Recommended Posts

ok i think and hope this will be my last issue with this site.

 

i have two forms on the same contact page, but right now theyre using the same error label. this means if ONE has an error, both forms show as that same error.  id like to somehow separate this and give each one its own label.

i tried doing like error[2] for the 2nd button instead of error[] but then i didnt know what to change the actual "error label" to. do i changed the "$errors = array();" part? to create a second label? i tried to google on it and couldnt figure it out.  thanks a million to anyone who even reads :)

 

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

 

so my question basically is, how do i use this code below to create a second error case AND label please!!

<?php
if ($_POST['send']) {
$errors = array();
if ($_POST['captcha'] != $_SESSION['captchacode']) {
	$errors[] = "You didn't enter the correct letters!";
}

 

 

+

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

Link to comment
Share on other sites

yeah i was seeing something when i googled like that i just didnt know if it applied

or how to apply it. that kind of helps though what would it be? this is the part confuses me, would it be like this?

<font color="red"><b><?php
if (isset($errors)) {
foreach ($errors as $error) {
	echo("<p>$error[form2][error2]<p>\n");
}
}
?></font></b>

Link to comment
Share on other sites

Well, you have to change the displaying errors code too.

 

//

$errors['form1'][0] = 'asda';
$errors['form1'][1] = 'aasdsda';
$errors['form1'][2] = 'asddwa';
$errors['form2'][0] = 'asdwdwwwwwa';
$errors['form2'][1] = 'a2dafsda';
$errors['form2'][2] = 'asiuuuuda';

foreach($errors['form1'] as $error)
{
    echo $error . "<br />";
}

Link to comment
Share on other sites

i did.

<?php

if ($_POST['send2']) {

$errors = array();

if ($_POST['captcha2'] != $_SESSION['captchacode']) {

$errors[2] = "You didn't enter the correct letters!";

}

if ($_POST['email1'] != $_POST['email2']) {

$errors[form2][error2] = "EMAIL 1 != EMAIL2!!!";

}

 

if (!count($errors)) {

// IMPORTANT: If you don't call this the

// user will keep getting the SAME code!

captchaDone();

$message = $_POST['email2'];

$body = "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

?>

 

Link to comment
Share on other sites

I would just add another array, if you know your giong to have 2 forms and only 2 forms it should be no problem:

if ($_POST['send']) {
$errors_form2 = array();

if ($_POST['captcha_form_2'] != $_SESSION['captchacode']) {
	$errors_form2[] = "You didn't enter the correct letters!";
}

 

hope this helps

Link to comment
Share on other sites

hmm i tried to transfer it

<?php
if ($_POST['send2']) {
$errors_form2 = array();
if ($_POST['captcha2'] != $_SESSION['captchacode']) {
	$errors_form2[] = "You didn't enter the correct letters!";
}
if ($_POST['email1'] != $_POST['email2']) {
	$errors_form2[] = "EMAIL 1 != EMAIL2!!!";
}

 

 

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

Link to comment
Share on other sites

what am i doing wrong :( :( :( :(

 

<?php
if ($_POST['send2']) {
$errors_form2 = array();
if ($_POST['captcha2'] != $_SESSION['captchacode']) {
	$errors[] = "You didn't enter the correct letters!";
}
if ($_POST['email1'] != $_POST['email2']) {
$errors_form2[] = "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();

 

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

Link to comment
Share on other sites

*sigh.

 

i tried this method too and im failing

<?php
if ($_POST['send2']) {
$errors['abc'] = array();
if ($_POST['captcha2'] != $_SESSION['captchacode']) {
	$errors['abc'] = "You didn't enter the correct letters!";
}
if ($_POST['email1'] != $_POST['email2']) {
$errors['abc'] = "The two emails do not match!!!!!!!!!!!!!!";
}

+ i tried this next to the text box AND at the bottom where the next code im going to post is

<?php if(isset($errors['abc'])) echo $errors['abc']; ?>

 

<font color="red"><b><?php
if (isset($errors['abc'])) {
foreach ($errors['abc'] as $error) {
	echo("<p>$error<p>\n");
}
}
?>
</font>

Link to comment
Share on other sites

This is pretty much what it should look like, I misread your original post.

 

<?php
if ($_POST['send']) {

$errors = array();

if ($_POST['captcha2'] != $_SESSION['captchacode']) {
	$errors['captcha2'] = "You didn't enter the correct letters!";
}

if ($_POST['email1'] != $_POST['email2']) {
	$errors['email2'] = "EMAIL 1 != EMAIL2!!!";
}

if (!count($errors)) {
	captchaDone();
	$message = $_POST['email2'];
	$body = "Message: $message";
	mail($myaddress, 'Contact Form Submission', $body);
}
}else{

$captcha_error = (isset($errors['captcha2']))? $errors['captcha2'] : NULL;
$email_error = (isset($errors['email2']))? $errors['email2'] : NULL;

echo('
	<form action="" method="post">
		<input type="text" name="captcha2" />'.$captcha_error.'<br />
		<input type="text" name="email1" /><br />
		<input type="text" name="email2" />'.$email_error.'<br />
		<input type="submit" value="Send" name="send" />
		<br/>
		'.((count($errors) >= 1)? 'Please correct the errors before continuing.' : NULL).'
	</form>
');
}
?>

 

hope this helps

Link to comment
Share on other sites

that wont even load :(

i hate programming so much.

thats a completely different setup.

 

i put that immediately after the other php if/else statements and it just doesnt load.

i dont understand this code enough to mess with it at all. there is no way to keep my original format? the send button works perfect, i just cant get send2 to work correct.

theres no way to get one of the 2 methods i was trying to use to work right? :(

thanks so much. idk what else to do.

Link to comment
Share on other sites

i dont get why neither of these will print an error for me

 

<?php if(isset($errors['abc'])) echo $errors['abc']; ?>



<font color="red"><b><?php
if (isset($errors['abc'])) {
foreach ($errors['abc'] as $error) {
	echo("<p>$error<p>\n");
}
}
?>
</font>

Link to comment
Share on other sites

sum of problem

 

this code i have works PERFECT. i just need 'send2' to send its error to a separate label, and how to call that label under the correct form.

 

<?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 (!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
?>
<html>
<head>
<title>Message Sent</title>
</head>
<body>
<h1>Message Sent</h1>
Thank you for using our handy contact form.
<p>
<!-- Generate a link back to ourselves -->
<a href="<?php echo $SERVER['SCRIPT_URL']?>">Contact Us Again</a>
</body>
</html>
<?php
	// Exit now to prevent the original form from
	// appearing again
	exit(0);
}
}
?>
<?php
if ($_POST['send2']) {
$errors = array();
if ($_POST['captcha2'] != $_SESSION['captchacode']) {
	$errors[] = "You didn't enter the correct letters22222!";
}
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();
$message = $_POST['email2'];
$body = "$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
?>
<html>
<head>
<title>Message Sent</title>
</head>
<body>
<h1>Message Sent</h1>
Thank you for using our handy contact form.
<p>
<!-- Generate a link back to ourselves -->
<a href="<?php echo $SERVER['SCRIPT_URL']?>">Contact Us Again</a>
</body>
</html>
<?php
	// Exit now to prevent the original form from
	// appearing again
	exit(0);
}
}
?>

 

plus

 

 

<form method="POST" action="<?php echo $SERVER['SCRIPT_URL']?>"> 
</tr>
<tr>
<td valign="top"> 
  <label for="name">Name:</label>
</td>
<td valign="top">
  <input type="text" name="email1" id="email1" MAXLENGTH=25 value="<?php if (!empty($_POST['email1'])) { echo  $_POST['email1']; } ?>" />
</td>
</tr>
<tr>
<td valign="top"> 
  <label for="phone">Phone:</label>
</td>
<td valign="top">

  <input type="text" name="email2" id="email2" MAXLENGTH=12 value="<?php if (!empty($_POST['email2'])) { echo  $_POST['email2']; } ?>" />
</td>
</tr><br><br>
<td valign="top"><input name="captcha" 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>
<td colspan="2" style="text-align:center">
<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");
}
}
?></font></b>


</td>
</tr>
</table>
</form>

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.