Jump to content

SkyRanger

Members
  • Content Count

    727
  • Joined

  • Last visited

Posts posted by SkyRanger


  1. Having a validation issue when a person enters a - in there name it is kicking it back as invalid.

    For axample:

    Mary-Ann  Invalid 
    Mary Ann Valid

    Tried including the - but causing myself a lot of grief.

    function filterkudoagent($field){
        // Sanitize user name
        $field = filter_var(trim($field), FILTER_SANITIZE_STRING);
    
        // Validate user name
        if(filter_var($field, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
            return $field;
        } else {
            return FALSE;
        }
    }

     


  2. Awesome Barand thank you.  I also see what I can start it on any day.  Again thank you.  Much easier than what I was attempting to do and PS: This link in your signature.  Still reading it over. Thank you


  3. I am currently working on a date range script and wondering if anybody think of an easier way to do this, doing up to next 8 weeks?  This one starts on a Sunday. I also need to do one starting on a Monday (will figure that one later)

    $thisweek = date("Y-m-d");
    $week = date('w', strtotime($thisweek));
    $date = new DateTime($thisweek);
    $firstWeek = $date->modify("-".$week." day")->format("M d");
    $endWeek = $date->modify("+6 day")->format("M d");
    echo $firstWeek." - ";
    echo $endWeek;
    
    $nextweek = date(("Y-m-d"), strtotime("+7 Days"));
    $week1 = date('w', strtotime($nextweek));
    $date1 = new DateTime($nextweek);
    $firstWeek1 = $date1->modify("-".$week1." day")->format("M d");
    $endWeek1 = $date1->modify("+6 day")->format("M d");
    echo $firstWeek1." - ";
    echo $endWeek1;

     


  4. Thanks Barand, I actually got it to work perfectly from the Sept 9th post you helped me with but been away for a bit and first time back to comment on benanamen post and try to solve another problem I posted in a different through with pulling random posts that I know I have done dozens of times but having a brain meltdown...lol


  5. I am trying to figure out how to populate a column that was added after the fact with this:

    function randkey($j = 10){
        $string = "";
        for($i=0; $i < $j; $i++){
            $x = mt_rand(0, 2);
            switch($x){
                case 0: $string.= chr(mt_rand(97,122));break;
                case 1: $string.= chr(mt_rand(65,90));break;
                case 2: $string.= chr(mt_rand(48,57));break;
            }
        }
        return $string;
    }

    This is what I currently have and you can guess how this turns out (same key in all rows):

    $randomkey =  randkey();
    $status = '1';
    
    
            $wpdb->update(
                $sqltable,
                array(
                    'randkey' => $kudoomkey,
                     ),
               array('status' => $status),
               array(
                    '(%s)'
                     ),
                array( '%d' )
                     );

  6. Hi mac_gyver. For some reason not sure what happened with that script. It actually is(was) working in another part of my plugin but for some reason not sure if I typed something wrong in the new part of the program.  I squashed the latest validation check above as it was causing nightmares.  I am currently working on securing the validation as I got it working almost the way it is needed but still having a problem with one field.  The account one that barand has provided assistance on.  person leaves account field empty should not give error. When enters data into field check field to ensure they are only numbers.

    if (isset($_POST['account']) && ctype_digit($_POST['account'])) {
        // OK
    }
    else {
        $accountErr = "Only numbers are permitted or leave blank";
    }

     


  7. Run in to a new issue and still having issue with code advised of Barand.  Even if there are errors the info is still submitting to database and if somebody does not enter anything in the account field it is stating that is required.

     if( isset($_POST['submit']) )
        {
    
        if(empty($_POST['kudoagent']))
    $msg_name = "You must supply agent name";
    $name_subject = $_POST['kudoagent'];
    $name_pattern = '/^[a-zA-Z ]*$/';
    preg_match($name_pattern, $name_subject, $name_matches);
    if(!$name_matches[0])
    $msg2_name = "Only alphabets and white space allowed";
    
        if(empty($_POST['agentloc']))
    $msg_agloc = "You must select a location";
    
        if(empty($_POST['kudoclient']))
    $msg_kclient = "You must select a queue";
    
        if(empty($_POST['kudocust']))
    $msg_custname = "You must supply customer name";
    $custname_subject = $_POST['kudocust'];
    $custname_pattern = '/^[a-zA-Z ]*$/';
    preg_match($custname_pattern, $custname_subject, $custname_matches);
    if(!$custname_matches[0])
    $msg2_custname = "Only alphabets and white space allowed";
    
        if(empty($_POST['kudomsg']))
    $msg_kmsg = "You must enter a kudos";
    
        if (isset($_POST['account']) && ctype_digit($_POST['account'])) {
        // Nothing to output
    }
    else {
        // ERROR
      $msg = "Only number are permitted";
    }
    
    }
    
        if(isset($_POST['submit'])){
        if($msg_name=="" && $msg2_name=="" && $msg_agloc=="" && $msg_kclient=="" && $msg_custname=="" && $msg2_custname=="" && $msg_kmsg=="")
        $msg_success = "Kudos has been submitted";
    
         global $wpdb;
                $table = $tablename;
                $kudokey = randkey();
                $kudoposted = date("Y-m-d H:i:s");
                $data = array(
                    'kudoid' => '',
                    'kudomsg'    => $_POST['kudomsg'],
                    'kudoagent' => $_POST['kudoagent'],
                    'kudoagentid' => $_POST['kudoagentid'],
                    'kudocust'    => $_POST['kudocust'],
                    'kudoacct' => $_POST['kudoacct'],
                    'kudoclient'    => $_POST['kudoclient'],
                    'kudoloc' => $_POST['agentloc'],
                    'kudoentry'    => $kudoposted,
                    'kudoadmin'    => $_POST['kudoadmin'],
                    'kudopic'     => $_POST['kudobanner'],
                    'kudostatus'   => '0',
         			'kudokey'  => $kudokey,
                );
                $format = array(
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s'
                );
                $success=$wpdb->insert( $table, $data, $format );
                if($success){
            /*
            echo "<blockquote class=\"otro-blockquote\">";
    		echo nl2br($_POST['kudomsg']);
    		echo "<span>";
    		echo "<b>Kudos for:</b> " .$_POST['kudoagent']. " - " .$_POST['kudoagentid']. ", ".$_POST['agentloc'];
      		echo "<br>By: ".$_POST['kudocust']. ", " . date("F j, Y g:i a", strtotime($kudoposted));
      		echo "<br/>" .$_POST['kudoacct'];
      		echo "<br/> Submitted By: " .$_POST['kudoadmin'];
    		echo "</span></blockquote>";
    		$urlparts = parse_url(home_url());
            $kudourl = $urlparts['host'];
            */
    
             echo "<div class='success_msg'>".$msg_success."</div>";
    
             }
    
            }

     


  8. Sorry maxxd

     if( isset($_POST['submit']) )
        {
    
        if(empty($_POST['kudoagent']))
    $msg_name = "You must supply agent name";
    $name_subject = $_POST['kudoagent'];
    $name_pattern = '/^[a-zA-Z ]*$/';
    preg_match($name_pattern, $name_subject, $name_matches);
    if(!$name_matches[0])
    $msg2_name = "Only alphabets and white space allowed";
    
        if(empty($_POST['agentloc']))
    $msg_agloc = "You must select a location";
    
        if(empty($_POST['kudoclient']))
    $msg_kclient = "You must select a queue";
    
        if(empty($_POST['kudocust']))
    $msg_custname = "You must supply customer name";
    $custname_subject = $_POST['kudocust'];
    $custname_pattern = '/^[a-zA-Z ]*$/';
    preg_match($custname_pattern, $custname_subject, $custname_matches);
    if(!$custname_matches[0])
    $msg2_custname = "Only alphabets and white space allowed";
    
    /*This is the issue part*/
    	
    	if(empty($_POST['account']))
    $acct_subject = $_POST['account'];
    $acct_pattern = '/^[0-9]*$/';
    preg_match($acct_subject, $aact_matches);
    if(!$acct_matches[0])
    $msg_acct = "Only numbers are allowed";
    
    /*end of issue part*/
    
        if(empty($_POST['kudomsg']))
    $msg_kmsg = "You must enter a kudos";
    
    }
    
        if(isset($_POST['submit'])){
        if($msg_name=="" && $msg2_name=="" && $msg_agloc=="" && $msg_kclient=="" && $msg_custname=="" && $msg2_custname=="" && $msg_kmsg=="" && msg_acct=="")
        $msg_success = "Kudos has been submitted";

     


  9. I am working on a form validation script and not sure how to approach this.  I can validate current entries that are required but I am trying to figure out how to validate an entry only if submitted and ignored if field is empty.

    /*form field*/
    <input type="text" name="account">
    <?php
    echo "<div class='note'>".$msg_acct."<br/>";
    
    
    
    /*This is in the validation script*/
    if(empty($_POST['account']))
    $acct_subject = $_POST['account'];
    $acct_pattern = '/^[0-9]*$/';
    preg_match($acct_subject, $aact_matches);
    if(!$acct_matches[0])
    $msg_acct = "Only numbers are allowed";

     


  10. Thanks maxxd. Yeah once I get the bugs all worked out and start putting everything together I am am going to be securing the crap out of this thing.  That is all I need is to leave an open hole for somebody to access a businesses server.


  11.         echo "<table>";
    
                    echo "<form name='FormData' method='post' action=''>";
    
                    echo "<thead><th>Name</th><th>Email</th><th>
                    <button type='submit' value='kudoemaildelete' class='formbutton' name='kudoemaildelete' />Delete</button>
                    </th></thead>";
                $kudolistem = $wpdb->get_results( "SELECT * from $tableemname where kuemqueue = '$kemail->kuemqueue'" );
                foreach ($kudolistem as $kudosndem) {
                    $kuemid = $kudosndem->kuemid;
                    echo "<tr>";
                    echo "<td>" .$kudosndem->kuemname. " </td><td>" .$kudosndem->kuemaddy. "</td><td><center><input name='kuemid[]' type='checkbox' id='checkbox[]' value=" .$kuemid. "></center></td>";
                    echo "</tr>";
    
                }
                echo "</form>";
                echo "</table>";

    It is probably something so stupid I am missing.  I have tried both _POST and  _GET

×
×
  • 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.