Solved

Search a POST var

Posted on 2008-06-11
7
181 Views
Last Modified: 2010-04-21
How could you search a post (that was like below in the code area it's $_POST["dataArray"] )  so i could do something like this:

function screachPOST() {
foreach(PostItem) {
if "Pick" is there {
            send error
            form="notComplete";
      }else{
            form="complete";
}
if "na" is there{
            send error
            form="notComplete";
      }else{
            form="complete";
}
if is not a phone number {
            send error
            form="notComplete";
      }else{
            form="complete";
}

if form="complete" {
 send email();
 send completed message
}

This is a POST that comes from flash if it makes a diff and if someone wanted to go the distance how to send the error back would be nice as well... I'm open to ideas here, I just have to work with the one string of var...

I have another post that relates to this as well if it would help with this...
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23477927.html

Thank you for the help
jeremyBass
{em_data_rec_v:na},{em_data_rec_d:na},{em_data_rec_di:na},{appstate_cb:pick},{Job_Picks`0|Unit Secretary Medical Unit},{Job_Picks`1|UNIT SECRETARY - SURGICAL UNIT},{row|0,employer|asdf,address|asdf,phone|asdf,supervisor|asdf,contact|false,wage|asdf,duties|asdf,from|Thu Jun 5 00:00:00 GMT-0700 2008,to|Fri Jun 13 00:00:00 GMT-0700 2008,reason|asdf},{row|1,employer|new Employee,address|asdf,phone|asdf,supervisor|asdf,contact|false,wage|asdf,duties|asdf,from|Mon Jun 9 00:00:00 GMT-0700 2008,to|Mon Jun 2 00:00:00 GMT-0700 2008,reason|asdf}

Open in new window

0
Comment
Question by:jeremyBass26
  • 5
  • 2
7 Comments
 
LVL 4

Author Comment

by:jeremyBass26
ID: 21765562
if it helps here is what i have so far on the flash side
var emailResponse:LoadVars = new LoadVars();

    emailResponse.onLoad = function(success:Boolean) {

    if (success) {

            debug_txt.text = this.result;

				ExternalInterface.call("formSubmit");

	trace("Submited");

	trace(postVars.dataArray);

    } else {

            debug_txt.text = "error downloading content";

    }

    };

    var postVars:LoadVars = new LoadVars();

    postVars.dataArray = FullArray;

    postVars.sendAndLoad("examples/example_011.php", emailResponse, "POST");

Open in new window

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 21773376
I don't know anything about the flash side, but here's one way to validate in PHP:
<?

$form_complete=TRUE;

$err_msg = '';

$my_fields=array('namefield','datefield','phonefield','otherfield');

foreach ($my_fields as $checkfield) {

  if (!isset($_POST['checkfield'])) { $form_complete=FALSE; $err_msg="Need $checkfield!\n"; }

  // you can validate individual keys here

  // at each step, if anything is wrong, set $form_complete=FALSE

  // and put a reason in $err_msg

  switch ($checkfield) {

    case 'namefield': // check for name validity

      break;

    case 'datefield': // check for date validity

      break;

    case 'phonefield': // check for phone format

      break;

    case 'otherfield': // check for whatever

      break;

  }

}

if (!$form_complete) {

  // something went wrong

  $_SESSION['error_message'] = $err_msg;

  header('location:back_to_my_form.php');

  die();

}

// otherwise, everything is yay.  Get it done.

?>

Open in new window

0
 
LVL 4

Author Comment

by:jeremyBass26
ID: 21773498
if the data that is sent to php... the var was = to:

{em_data_rec_v:na},{em_data_rec_d:na},{em_data_rec_di:na},{appstate_cb:pick},{Job_Picks`0|Unit Secretary Medical Unit},{Job_Picks`1|UNIT SECRETARY - SURGICAL UNIT},{row|0,employer|asdf,address|asdf,phone|asdf,supervisor|asdf,contact|false,wage|asdf,duties|asdf,from|Thu Jun 5 00:00:00 GMT-0700 2008,to|Fri Jun 13 00:00:00 GMT-0700 2008,reason|asdf},{row|1,employer|new Employee,address|asdf,phone|asdf,supervisor|asdf,contact|false,wage|asdf,duties|asdf,from|Mon Jun 9 00:00:00 GMT-0700 2008,to|Mon Jun 2 00:00:00 GMT-0700 2008,reason|asdf}
 

would what your sugesting pick out em_data_rec_v (which is the name to which has the value of na)
or just 'Job_Picks' ?

if yes how would you look in to this?
{row|1,employer|new Employee,address|asdf,phone|asdf,supervisor|asdf,contact|false,wage|asdf,duties|asdf,from|Mon Jun 9 00:00:00 GMT-0700 2008,to|Mon Jun 2 00:00:00 GMT-0700 2008,reason|asdf}

where it's   "Name"|"Value",    ?

your right it is to validate ... i should have put that up... thanks for the help here...


code \n
{em_data_rec_v:na},

{em_data_rec_d:na},

{em_data_rec_di:na},

{appstate_cb:pick},

{Job_Picks`0|Unit Secretary Medical Unit},

{Job_Picks`1|UNIT SECRETARY - SURGICAL UNIT},

{row|0,employer|asdf,address|asdf,phone|asdf,supervisor|asdf,contact|false,wage|asdf,duties|asdf,from|Thu Jun 5 00:00:00 GMT-0700 2008,to|Fri Jun 13 00:00:00 GMT-0700 2008,reason|asdf},

{row|1,employer|new Employee,address|asdf,phone|asdf,supervisor|asdf,contact|false,wage|asdf,duties|asdf,from|Mon Jun 9 00:00:00 GMT-0700 2008,to|Mon Jun 2 00:00:00 GMT-0700 2008,reason|asdf}

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 21784248
Tricky.  The easiest way would be with the PCRE functions.  Take a look at them here:

http://www.php.net/manual/en/ref.pcre.php

Specifically, take a look at preg_match_all().  Here's a possible untested example for you:
<?

$pattern='/\{([^}]+)\},?/';

$search=$the_data_you_posted_last

$matches=array();
 

$match=preg_match_all($pattern,$search,$matches);

// $matches[0][0] should be '{em_data_rec_v:na},'

// $matches[0][1] should be 'em_data_rec_v:na'

// $matches[1][0] should be '{em_data_rec_d:na},'

?>

Open in new window

0
 
LVL 4

Author Comment

by:jeremyBass26
ID: 21784275
Looks like a promising route... i'll get back on this... :)
0
 
LVL 4

Author Comment

by:jeremyBass26
ID: 21817476
I have been going rounds on this... and have got no ware fast lol... but
FYI... I will be out after 4pm PST and will be gone for my son's surgery for the next four days... so I will not be able to do much if any thing...
thanks again...
jeremyBass
0
 
LVL 4

Author Closing Comment

by:jeremyBass26
ID: 31466419
sorry for the delay... thanks for the help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now