Forum Moderators: coopster

Message Too Old, No Replies

$ POST array issues

Issues with post

         

Matthew1980

9:19 pm on Mar 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of webmaster world,

I have a problem which with my coffee pot empty I can't fathom!

I have two submit buttons on a form (preview & send) I want to know that if preview is set, is there a way to tell if the rest of the array is empty apart from the ['submit'] =>"preview" key.

Hope that makes sense, I know I can do it just by naming each element and checking to see if it is empty, but that just seems long winded to me.

would: array_walk($_POST, 'isset'); be in the right area?

Any suggestions appreciated...

Right off for the coffee pot!

Cheers,

MRb

Readie

9:51 pm on Mar 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A foreach loop should do it.

foreach($_POST as $key => $val) {
if((!isset($val) || $val == "") && $key != "submitButtonName") {
echo $key . ' is empty.';
}
}

Matthew1980

9:59 pm on Mar 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Readie,

Wood for the tree's once again springs to the front of my mind! That was obvious, should have realised this. Doh ;-p

Cheers

MRb

Matthew1980

8:38 am on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Readie,

Ideally I would like to do a script redirect if the 'submitbutton' name was the only key populated, maybe the way I am aproaching this is a little convoluted, I'm looking at other methods, but for now it's just a matter of getting something simplified as at the moment I have:-


if(!isset($_POST['name']) || !isset($_POST['email']) && isset($_POST['preview']) && ($_POST['preview'] == "preview"))
{
//redirect
}


Cheers,

MRb

Readie

9:23 am on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, to do that I'd personally do something like this:

$check = 0;
foreach($_POST as $key => $val) {
if($key != "submitButtonName" && isset($val) && $val != "") {
$check++;
}
}

if($check > 0){
// Redirect
} else {
// Preview
}