Results 1 to 6 of 6

Thread: Each send button with its own error 'label'/...array?

  1. #1
    Join Date
    Oct 2010
    Posts
    75
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Each send button with its own error 'label'/...array?

    I give up. I've probably been messing with this around 5 hours now and am getting no where. This is the last 'complicated' feature i THINK i need on this site, but, as far as Ive come (and even completed the last form) i cant get this to make a second 'label' for reporting errors.

    this code i have works PERFECT. send1 is checking a form and captcha and sending if everything is good.
    send2 checks email1 and email2, makes sure they match, makes sure the captcha2 text box is correct and if so, sends it. i got this to work perfectly but if theres an error, send2 sends its error to the same place as send1. i just need 'send2' to send its error to a separate label, and how to call that label.
    right now both errors are sending to this label, whereever i put this the follow code:

    thanks in advance im so lost. i know NO php btw. just learning it trying to get this function going.


    PHP Code:
    <font color="red"><b><?php
    if (isset($errors)) {
       foreach (
    $errors as $error) {
          echo(
    "<p>$error<p>\n");
       }
    }
    ?></font></b>
    and i need to make a 2nd one of those, for 'send2' to send its errors to.

    full code:

    PHP Code:
    <?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!!!!
    PHP Code:
    <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()?>">&nbsp;&nbsp;

      <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>

  2. #2
    Join Date
    Oct 2010
    Posts
    75
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    ive been at it about 8 hours now literally haha
    tried about 3 different methods
    and i am clueless.
    either both errors post on both sides
    or, when ur working on one form, each forms error shows under that form if u mess up only ONE form

  3. #3
    Join Date
    Oct 2010
    Posts
    75
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    damn 107 views and nothin? is it that hardd to do can someone tell me? if its that big of an issue maybe ill have to leave it or something idk.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Hey! Sorry for the delay in a response. Find this code:
    Code:
    <?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 
    ?>
    And change all the $errors (highlighted) to $errors2.

    Now, where you want your errors coming from $send2 to be, place the following code.
    Code:
    <?php 
    if (isset($errors2)) { 
       foreach ($errors2 as $error) { 
          echo("<p>$error<p>\n"); 
       } 
    } 
    ?>
    Good luck
    Jeremy | jfein.net

  5. #5
    Join Date
    Oct 2010
    Posts
    75
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    i am...
    almost speechless
    ..thats all?
    i am so glad
    this stupid litttle feature i needed
    is over.
    thank you
    so
    much.

    thanks to everyone else too.
    i cant believe it was that easy.
    i kinda feel a bit dumb LOL but i do know NO php
    thanks 324923423894892342348823482934892 million,
    Last edited by mat420; 02-20-2011 at 01:44 PM. Reason: sdfsdfdsfsdfsdfsdf

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem, I'm glad to help

    Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved when an issue is fixed. To make the status of the thread resolved:
    1. Go to your first post
    2. Edit your first post
    3. Click "Go Advanced"
    4. In the dropdown next to the title, select "RESOLVED"
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •