By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,722 Members | 1,904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,722 IT Pros & Developers. It's quick & easy.

help with posting conditional if statement

P: n/a
Art
Can anyone help. I've tried scaling down a script to the bare minimum and
it still is not working correctly. What I think should happen is that when
the field app_fname is blank, that $hold_chk will get set to 1 and the 1st
if statement will be executed. What actually happens is that when I hit
submit, the form stays where it is, for example if the form where the submit
button is located is on the form other.php, then when I hit submit this is
where it stays. If I then hit the submit button a 2nd time, it post to the
some.php form. I've tried this script without the conditional if(isset()
and it works. I need to have the isset() otherwise the form displays all
empty fields as soon as it loads, before the submit button is hit. Any help
would be appreciated. After working on this for 2 weeks it seems like i'm
stuck.

Thanks
Art

<?php

$holdchk = 0;

if (isset($_POST['B1'])) {

echo "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk == 1 ){
echo "<form method=\"POST\" action=\"some.php\">";

}

if ($holdchk == 0 ){
echo "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<form method="POST" action="">

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

May 4 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Message-ID: <ry*******************@bignews7.bellsouth.netfro m Art
contained the following:
>After working on this for 2 weeks it seems like i'm
stuck.
Don't multipost. And haven't we seen this before?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 4 '07 #2

P: n/a
Art
Sort of, but this is a scaled down version of the code, which was requested.
I'm still stuck and still trying to understand why it's not working.

Thanks
Art
"Geoff Berrow" <bl******@ckdog.co.ukwrote in message
news:8c********************************@4ax.com...
Message-ID: <ry*******************@bignews7.bellsouth.netfro m Art
contained the following:
>>After working on this for 2 weeks it seems like i'm
stuck.

Don't multipost. And haven't we seen this before?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

May 4 '07 #3

P: n/a
Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty

S

"Art" <c_***@bellsouth.netwrote in message
news:ry*******************@bignews7.bellsouth.net. ..
Can anyone help. I've tried scaling down a script to the bare minimum and
it still is not working correctly. What I think should happen is that
when
the field app_fname is blank, that $hold_chk will get set to 1 and the 1st
if statement will be executed. What actually happens is that when I hit
submit, the form stays where it is, for example if the form where the
submit
button is located is on the form other.php, then when I hit submit this is
where it stays. If I then hit the submit button a 2nd time, it post to
the
some.php form. I've tried this script without the conditional if(isset()
and it works. I need to have the isset() otherwise the form displays all
empty fields as soon as it loads, before the submit button is hit. Any
help
would be appreciated. After working on this for 2 weeks it seems like i'm
stuck.

Thanks
Art

<?php

$holdchk = 0;

if (isset($_POST['B1'])) {

echo "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk == 1 ){
echo "<form method=\"POST\" action=\"some.php\">";

}

if ($holdchk == 0 ){
echo "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<form method="POST" action="">

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

May 4 '07 #4

P: n/a

"Simon Stewart" <ad*****@www.simonstewart.iewrote in message
news:5a*************@mid.individual.net...
Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty
And why is that?
May 4 '07 #5

P: n/a
Message-ID: <na*******************@bignews7.bellsouth.netfro m Art
contained the following:
>Sort of, but this is a scaled down version of the code, which was requested.
I'm still stuck and still trying to understand why it's not working.
And you took no notice of my post on the subject before. You are still
echoing html /before/ the<htmltag!

I think you need something like this:

<?php

$holdchk = 0;
if (isset($_POST['B1'])) {
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method=\"POST\" action=\"some.php\">";
}

if ($holdchk === 0 ){
$form.= "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 4 '07 #6

P: n/a
Simon Stewart wrote:
Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty
Why avoid isset?
I use that function in every script that receives clientinformation...
Couldn't life without it.

Personally I think your posted code is a bad example on how to solve it...
You need to read it twice and rethink it. Clear code is better and happens
to use isset().
Just my 2 cent of course...

Regards,
Erwin Moller
May 4 '07 #7

P: n/a
Erwin Moller kirjoitti:
Simon Stewart wrote:
>Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty

Why avoid isset?
I don't think he knows what he's talking about. isset is essential.
I use that function in every script that receives clientinformation...
Couldn't live without it.
Same here. And it's really handy when using forms with multiple submit
buttons, to see which was pressed. (print, edit, delete, for example.)
Personally I think your posted code is a bad example on how to solve it...
You need to read it twice and rethink it. Clear code is better and happens
to use isset().
Yeah, the example is indeed a bit messy. And concidering the level of
the OP, it's no help at all, it only confuses more. The OP requires the
"php for dummies" answer.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 4 '07 #8

P: n/a
Art
Geoff, I tried modifying the code with your suggestions. It had the effect
of disabling the submit button. It seems like there has to be <form
method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.

Thanks
Art
"Geoff Berrow" <bl******@ckdog.co.ukwrote in message
news:lo********************************@4ax.com...
Message-ID: <na*******************@bignews7.bellsouth.netfro m Art
contained the following:
>>Sort of, but this is a scaled down version of the code, which was
requested.
I'm still stuck and still trying to understand why it's not working.

And you took no notice of my post on the subject before. You are still
echoing html /before/ the<htmltag!

I think you need something like this:

<?php

$holdchk = 0;
if (isset($_POST['B1'])) {
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method=\"POST\" action=\"some.php\">";
}

if ($holdchk === 0 ){
$form.= "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

May 4 '07 #9

P: n/a
Message-ID: <DX*******************@bignews8.bellsouth.netfro m Art
contained the following:
>Geoff, I tried modifying the code with your suggestions. It had the effect
of disabling the submit button. It seems like there has to be <form
method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.
I was in a hurry last night because I was going out and not really
paying attention. Your code /is/ still seriously screwed but that
wasn't the solution.

Can you please describe what you /expect/ it to do? I'm sure the answer
is very simple.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 5 '07 #10

P: n/a
Geoff Berrow kirjoitti:
Message-ID: <DX*******************@bignews8.bellsouth.netfro m Art
contained the following:
>Geoff, I tried modifying the code with your suggestions. It had the effect
of disabling the submit button. It seems like there has to be <form
method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.

I was in a hurry last night because I was going out and not really
paying attention. Your code /is/ still seriously screwed but that
wasn't the solution.

Can you please describe what you /expect/ it to do? I'm sure the answer
is very simple.
Your sample was missing the default form. It only worked in the case
when something was posted, but in the case the page is opened the first
time, there is no form tag at all...

So, once again, from the top...

<?php

$holdchk = 0;
if (isset($_POST['B1'])) { // if the form was submitted
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method='POST' action='some.php'>";
}

if ($holdchk === 0 ){
$form.= "<form method='POST' action='other.php'>";

}
} else { // no form was submitted
$form = "<form method='POST' action='{$_SERVER['PHP_SELF']}'>";
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

I think this is what Geoff meant, he just forgot the default case. :)

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 5 '07 #11

P: n/a
Message-ID: <f1**********@nyytiset.pp.htv.fifrom Rami Elomaa contained
the following:
>I think this is what Geoff meant, he just forgot the default case. :)
LOL thanks Rami for seeing where I was going. :-)

But as I said, I'm sure we can find a far better way of accomplishing
what the OP wants to do.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 5 '07 #12

P: n/a
Art
Geoff, I'm just trying to have validation in my form. I check to see if
certain fields have values, if all the required fields have values, i want
to sent the data to another php form, that processes the request and sends
the data to a sql database and generates an email that a request has come
in.

The problem i'm having is that no matter what i do, the form will not submit
on the first click, even though all conditions are met. I've tested this by
echoing variables that let me know where i am in the code.

What's strange is that when i hit the submit button the 2nd time, it submits
ok.

I've tried your suggestions but the abscense of the form tag in the html
deactivated the submit button. I'm going to try the other suggestion.

You're also right in that it can no doubt be done better. I'm new to php
programming. I'm currently enrolled in a cis programming degreed course but
haven't gotten into my core curricula yet.

Thanks for your patience
Art
"Rami Elomaa" <ra*********@gmail.comwrote in message
news:f1**********@nyytiset.pp.htv.fi...
Geoff Berrow kirjoitti:
>Message-ID: <DX*******************@bignews8.bellsouth.netfro m Art
contained the following:
>>Geoff, I tried modifying the code with your suggestions. It had the
effect of disabling the submit button. It seems like there has to be
<form method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.

I was in a hurry last night because I was going out and not really
paying attention. Your code /is/ still seriously screwed but that
wasn't the solution.

Can you please describe what you /expect/ it to do? I'm sure the answer
is very simple.

Your sample was missing the default form. It only worked in the case when
something was posted, but in the case the page is opened the first time,
there is no form tag at all...

So, once again, from the top...

<?php

$holdchk = 0;
if (isset($_POST['B1'])) { // if the form was submitted
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method='POST' action='some.php'>";
}

if ($holdchk === 0 ){
$form.= "<form method='POST' action='other.php'>";

}
} else { // no form was submitted
$form = "<form method='POST' action='{$_SERVER['PHP_SELF']}'>";
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

I think this is what Geoff meant, he just forgot the default case. :)

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

May 5 '07 #13

P: n/a
>Geoff, I'm just trying to have validation in my form. I check to see if
>certain fields have values, if all the required fields have values, i want
to sent the data to another php form,
You do realize that if it's important to check certain fields for valid
values, that it is just as important to check those fields for the SECOND
form ALSO, I hope?
>that processes the request and sends
the data to a sql database and generates an email that a request has come
in.
May 6 '07 #14

P: n/a
Art kirjoitti:
Geoff, I'm just trying to have validation in my form. I check to see if
certain fields have values, if all the required fields have values, i want
to sent the data to another php form, that processes the request and sends
the data to a sql database and generates an email that a request has come
in.
So you'll be requesting the user to submit it twice? That's complicating
things unnecessarily. Once you have validated, just insert them into the
database right away. You can do that by including the processing page if
the fields check okay.

Like this:

if($_POST['submit']){

if(!empty($_POST['field'])){

// Here you include the processing script
include('some.php');
exit();

}

}

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 6 '07 #15

P: n/a
Art
Thanks Geoff, that worked.

Art
"Rami Elomaa" <ra*********@gmail.comwrote in message
news:f1**********@nyytiset.pp.htv.fi...
Art kirjoitti:
>Geoff, I'm just trying to have validation in my form. I check to see if
certain fields have values, if all the required fields have values, i
want to sent the data to another php form, that processes the request and
sends the data to a sql database and generates an email that a request
has come in.

So you'll be requesting the user to submit it twice? That's complicating
things unnecessarily. Once you have validated, just insert them into the
database right away. You can do that by including the processing page if
the fields check okay.

Like this:

if($_POST['submit']){

if(!empty($_POST['field'])){

// Here you include the processing script
include('some.php');
exit();

}

}

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

May 8 '07 #16

P: n/a
"Art" <c_***@bellsouth.netwrote in message
news:cCZ%h.24665$vD4.23811@bigfe9...
Thanks Geoff, that worked.

Art

No problem Fred. :)

--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
May 8 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.