The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 783 errorHandler->error
/showthread.php 26 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 783 errorHandler->error
/showthread.php 26 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/showthread.php 26 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 909 errorHandler->error
/showthread.php 26 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/showthread.php 26 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/showthread.php 26 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/showthread.php 137 forum_permissions
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key "mybb" - Line: 1952 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1952 errorHandler->error
/inc/functions_indicators.php 41 my_set_array_cookie
/showthread.php 629 mark_thread_read
Warning [2] Undefined property: MyLanguage::$ratings_update_error - Line: 5 - File: showthread.php(732) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/showthread.php(732) : eval()'d code 5 errorHandler->error
/showthread.php 732 eval
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions_user.php 844 is_member
/inc/functions_post.php 406 purgespammer_show
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "profilefield" - Line: 6 - File: inc/functions_post.php(474) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php(474) : eval()'d code 6 errorHandler->error
/inc/functions_post.php 474 eval
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "canonlyreplyownthreads" - Line: 660 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 660 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showimages" - Line: 741 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 741 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showvideos" - Line: 746 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 746 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions_user.php 844 is_member
/inc/functions_post.php 406 purgespammer_show
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "profilefield" - Line: 6 - File: inc/functions_post.php(474) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php(474) : eval()'d code 6 errorHandler->error
/inc/functions_post.php 474 eval
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "canonlyreplyownthreads" - Line: 660 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 660 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showimages" - Line: 741 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 741 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showvideos" - Line: 746 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 746 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "invisible" - Line: 1506 - File: showthread.php PHP 8.1.27 (Linux)
File Line Function
/showthread.php 1506 errorHandler->error
Warning [2] Undefined variable $threadnotesbox - Line: 30 - File: showthread.php(1533) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/showthread.php(1533) : eval()'d code 30 errorHandler->error
/showthread.php 1533 eval
Warning [2] Undefined variable $addremovesubscription - Line: 79 - File: showthread.php(1533) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/showthread.php(1533) : eval()'d code 79 errorHandler->error
/showthread.php 1533 eval



FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
email validation not working (api.php)
#1
A bit of an odd one...

Server-side email validation isn't working for some strange reason. I've tried changing the field name in case it conflicts with an already existing variable but no joy. The field is correctly repopulated in the event of a validation error elsewhere; it's merely refusing to validate (i.e. it's not being registered as a rule).

Everything else works a treat otherwise:
Code:
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/path/to/formtools/global/api/api.php');

// form settings
$_POST['form_tools_form_id']     = 6;
$_POST['item_name']             = "PayPal Donation";
$_POST['next_page']                = "/path/to/paypal_submit.php";
$_POST['mode']                     = "";    // initialize

// validate form
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $fields = array();
    
    $rules = array();
    $rules[] = "required,firstname,Please enter your first name.";
    $rules[] = "required,lastname,Please enter your last name.";
    $rules[] = "valid_email,email,Please enter a valid email address.";
    $rules[] = "required,amount,Please enter an amount.";
    
    $errors = array();
    $errors = validate_fields($_POST, $rules);
    
    if(empty($errors))
    {
        $fields = ft_api_init_form_page($_POST['form_tools_form_id']);
        
        $params = array("submit_button" => "submit",
                        "next_page"     => $_POST['next_page'],
                        "form_data"     => $_POST
                        );
        
        if($_POST['mode'] == "initialize")
        {
            $params['finalize'] = true;
        }
        ft_api_process_form($params);
    }
    else
    {
        $fields = array_merge($fields, $_POST);
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>Donation Form</title>
  <script type="text/javascript" src="includes/rsv.js"></script>
  <link rel="stylesheet" type="text/css" href="includes/main.css">
  <script type="text/javascript">
  <!--
  var rules = [];
  //rules.push("required,firstname,Please enter your first name.");
  //rules.push("required,lastname,Please enter your last name.");
  //rules.push("required,email,Please enter your email address.");
  -->
  </script>
  </head>
  <body>
<div class="title">Donate</div>
<p> Use the form below to donate. This is an <em>extended</em> example form for the <a href="http://docs.formtools.org/tutorials/paypal/" target="_blank">Form Tools 2 PayPal integration tutorial</a>. </p>
<div id="rsvError"></div>
<?php
if(!empty($errors))
{
    echo "<div class='error'>Please correct the following errors, and resubmit the form:".
         "<ul>";
    foreach ($errors as $error)
      echo "<li>$error</li>";
    echo "</ul></div><br />";
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" onSubmit="return rsv.validate(this, rules)">
    <input type="hidden" name="item_name" value="<?=@$fields['item_name']?>" />
    <table border="0" cellspacing="1">
    <tr>
        <td width="10" class="red">*</td>
        <td width="110">First Name</td>
        <td width="10"></td>
        <td><input type="text" name="firstname" id="firstname" value="<?=@$fields['firstname']?>" /></td>
      </tr>
    <tr>
        <td class="red">*</td>
        <td>Last Name</td>
        <td></td>
        <td><input type="text" name="lastname" id="lastname" value="<?=@$fields['lastname']?>" /></td>
      </tr>
    <tr>
        <td class="red">*</td>
        <td>Email Address</td>
        <td></td>
        <td><input type="text" name="email" id="email" value="<?=@$fields['email']?>" /></td>
      </tr>
    <tr>
        <td class="red"></td>
        <td>City</td>
        <td></td>
        <td><input type="text" name="city" id="city" value="<?=@$fields['city']?>" /></td>
      </tr>
    <tr>
        <td class="red">*</td>
        <td>Amount</td>
        <td align="right"><b>&pound;</b></td>
        <td><select name="amount" id="amount">
            <option value="" <?php if (@$fields['amount'] == "") echo "selected"; ?>>Select</option>
            <option value="2.00" <?php if (@$fields['amount'] == "2.00") echo "selected"; ?>>2.00</option>
            <option value="5.00" <?php if (@$fields['amount'] == "5.00") echo "selected"; ?>>5.00</option>
            <option value="10.00" <?php if (@$fields['amount'] == "10.00") echo "selected"; ?>>10.00</option>
          </select></td>
      </tr>
    <tr>
        <td></td>
        <td>Subscription</td>
        <td></td>
        <td><input type="checkbox" class="checkbox" name="cmd" id="cmd" value="_xclick-subscriptions" <?php if (@$fields['cmd']) echo 'checked="checked"'; ?> /></td>
      </tr>
    <tr>
        <td></td>
        <td>How often?</td>
        <td></td>
        <td><select name="p3" id="p3">
            <option value="" <?php if (@$fields['p3'] == "") echo "selected"; ?>>Select</option>
            <option value="1" <?php if (@$fields['p3'] == "1") echo "selected"; ?>>Monthly</option>
            <option value="4" <?php if (@$fields['p3'] == "4") echo "selected"; ?>>Quarterly </option>
            <option value="12" <?php if (@$fields['p3'] == "12") echo "selected"; ?>>Yearly</option>
          </select></td>
      </tr>
    <tr>
        <td class="red"></td>
        <td>Gift Aid</td>
        <td><input type="hidden" name="on0" id="on0" value="Donation with Gift Aid" /></td>
        <td><input type="checkbox" name="os0" id="os0" value="YES" <?php if (@$fields['os0']) echo 'checked="checked"'; ?> /></td>
      </tr>
    <tr>
        <td colspan="2"></td>
        <td colspan="2"><div style="padding-top: 5px;">
            <input type="submit" name="submit" value="submit" />
          </div></td>
      </tr>
  </table>
  </form>
</body>
</html>

Update:

Seems to be a problem with "valid_email" param; it works when i use this:

PHP Code:
$rules[] = "required,email,Please enter a valid email address."

but not this:

PHP Code:
$rules[] = "valid_email,email,Please enter a valid email address."

?
Update 2:

What a moron (me)! Just checked your validation script:

PHP Code:
// doesn't fail if field is empty
      
case "valid_email":
        
$regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
        if (isset(
$fields[$field_name]) && !empty($fields[$field_name]) && !preg_match($regexp$fields[$field_name]))
          
$errors[] = $error_message;
        break; 

I need to include BOTH rules to the field concurrently: valid_email AND required.

Makes perfect sense.

Reply
#2
Excellent! Glad you got it working. Smile

- Ben
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)