mat420 Posted February 18, 2011 Share Posted February 18, 2011 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"); } } ?> Quote Link to comment Share on other sites More sharing options...
kartul Posted February 18, 2011 Share Posted February 18, 2011 How about you make multi-dimensional array? $error[form1][error1] $error[form2][error1] Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 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> Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 nope. that error printed as 'Array' hmmm Quote Link to comment Share on other sites More sharing options...
kartul Posted February 18, 2011 Share Posted February 18, 2011 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 />"; } Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 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 ?> Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted February 18, 2011 Share Posted February 18, 2011 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 Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 if ($_POST['email1'] != $_POST['email2']) { $errors[form2][error2] = "EMAIL 1 != EMAIL2!!!"; Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 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"); } } ?> Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted February 18, 2011 Share Posted February 18, 2011 You need to change all the var names remember - and remember what foreach does with its "as" clause. if (isset($errors_form2)) { foreach ($errors_form2 as $error) { echo("<p>$error<p>\n"); } } hope this helps Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 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"); } } Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 send2 button now completely irresponsive. i added _form2 to the captcha part too, just incase that was the issue. Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 i know no php btw, probably why im such a pain ;/ haha i do appreciate it though ! im out of ideas :/ im gonna try to keep messing with it. Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 *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> Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 absolutely nothing will post here <?php if (isset($errors['abc'])) { foreach ($errors['abc'] as $error) { echo("<p>$error<p>\n"); } } ?> i even tried using error[abc] under "send" instead of send2 since i know the 'send' works =[ im clueless. Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted February 18, 2011 Share Posted February 18, 2011 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 Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 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. Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 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> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 18, 2011 Share Posted February 18, 2011 $errors['abc'] must not be set since isset($errors['abc']) is not true. Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 dk what that means exactly sorry. Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 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> Quote Link to comment Share on other sites More sharing options...
The Letter E Posted February 18, 2011 Share Posted February 18, 2011 nope. that error printed as 'Array' hmmm FYI if something prints as 'Array' do either a print_r($myarray) or var_dump($myarray) on it to give you a better idea of the structure you are working with. Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 18, 2011 Author Share Posted February 18, 2011 i honestly dont think i could even recreate whatever did that i got it exactly how i need errrors are posting just need the errors to post to separate spots take a look please http://aciddr0p.net/drtest/demo2.php "emails dont match!!" (left form) i want to only post on that side. and vice versa Quote Link to comment Share on other sites More sharing options...
mat420 Posted February 20, 2011 Author Share Posted February 20, 2011 problem completely solved. thanks all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.