homepage Welcome to WebmasterWorld Guest from 54.204.58.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
2 forms on same page, nested php
helenp




msg:4522566
 12:21 pm on Nov 26, 2012 (gmt 0)

Hi, As i cant pass vars by post using headers I am trying to use the same page, wich is really the best.
So I have a page in wich the content is in the last else in which there is a form with 2 radiobuttons to choose between.

The php checks if submitted without checking any,
if none is checked then an error message is displayed.
If some is checked then another content should be served depending on button choosed.

The script works perfect as the echos in the options are displayed correctly.
However what I want inside one of the option is another form.
This is the script shortened:
When I click on button enquierer I get the echo message enquiere correctly, but when I click on send the other form I go back to the initial start page, I dont get the echo ok:

<?php
if (isset($_POST['enviar2'])) {
if (empty($bookingway)) {
echo "<span class='style2'>Please choose instant booking or send enquirer and click on send again</span>";
}//if empty
else{
if ($bookingway=="instant"){
echo "instant";
}//if instant
if ($bookingway=="enquirer"){
echo "enquirer";
if (isset($_POST['enviar']))
{echo "OK"; }
?><form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" name="bookingways" id="bookingways">
<p align="center"><input class="boton" type="submit" name="enviar" value="Send"> </p>
</form>
<?php }//if enquirer
}//else
}//if enviar2
else {?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" name="bookingways" id="bookingways" onSubmit="return validate_form2 ( );">
<input type="hidden" name="propiedad" value="<?php print $propiedad;?>">
<p class="bookingway">
<input name="bookingway" type="radio" value="instant">Instant booking (I have read terms and conditions).<br>
<input name="bookingway" type="radio" value="enquirer">Send enquirer or book by email.
</p>
<p align="center"><input class="boton" type="submit" name="enviar2" value="Send"> </p>
<?php
}


Further explained:
if ($bookingway=="enquirer"){
echo "enquirer";
Until here it works perfect
if (isset($_POST['enviar']))
{echo "OK"; }
However this does not work, it gives the the last else in the script (the start content for the page)

Thanks,

 

helenp




msg:4522584
 1:47 pm on Nov 26, 2012 (gmt 0)

Of course, how stupid I am, when the page refreshes, it goes to the else as it starting from the beginning.
If I put the if post form bebore the other form I get the echo OK correctly, however I get the else message below, and I dont want it at all, think I tried everything but ther must be a way.
This works but gives me the else from the startpage below the echo OK:
if (isset($_POST['enviar']))
{echo "OK"; }
if (isset($_POST['enviar2'])) {

londrum




msg:4522590
 2:23 pm on Nov 26, 2012 (gmt 0)

its a bit complicated to understand, but if i've got it right then this line
if(isset($_POST['enviar']))
{ echo "OK"; }
is never going to say ok because it's inside the enviar2 loop.

the only way to get inside the
if(isset($_POST['enviar2'])){
loop is by submitting the form with the two radio buttons (
name="enviar2").

the 2nd form (
name="enviar") is then inside that loop. so
if(isset($_POST['enviar']))
{ echo "OK"; }
will never be OK. because when you submit it, you then go back outside the enviar2 loop

helenp




msg:4522593
 2:39 pm on Nov 26, 2012 (gmt 0)

Thanks Londrum,
Not sure I understood you either, if I get you right what I want to do is imposible.
With this code I enter page, get the form enviar2 visible, I choose radiobutton enquirer and click on send, I get as a result the echo "enquirer" and the button for sending form enviar.
I click on button for sending form enviar and the result is echo OK, but below the result I get also the last else with form enviar2 in it.
I want this result but I do NOT want the form enviar2 below.

This is what I have so far, wich gives me OK but gives me enviar2 below:


<?php
if (isset($_POST['enviar']))
{echo "OK"; }
if (isset($_POST['enviar2'])) {
if (empty($bookingway)) {
echo "<span class='style2'>Please choose instant booking or send enquirer and click on send again</span>";
}//if empty
else{
if ($bookingway=="instant"){
echo "instant";
}//if instant
if ($bookingway=="enquirer"){
echo "enquirer";
?><form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" name="bookingways" id="bookingways">
<p align="center"><input class="boton" type="submit" name="enviar" value="Send"> </p>
</form>
<?php
}//if enquirer
}//else

}//if enviar2
else{?> <form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" name="bookingways" id="bookingways" onSubmit="return validate_form2 ( );">
<p class="bookingway">
<input name="bookingway" type="radio" value="instant">Instant booking <br>
<input name="bookingway" type="radio" value="enquirer">Send enquirer or book by email.
</p>
<p align="center"><input class="boton" type="submit" name="enviar2" value="Send"> </p>
</form>

londrum




msg:4522595
 3:00 pm on Nov 26, 2012 (gmt 0)

now i understand... all you've got to do, i think, is change that final

else{

to

elseif(!isset($_POST['enviar'])){

i reckon that will work

helenp




msg:4522601
 3:49 pm on Nov 26, 2012 (gmt 0)

Thanks, I will try that, I was also thinking no way to change the else to an if.

helenp




msg:4522605
 3:56 pm on Nov 26, 2012 (gmt 0)

Thanks, that works like a charm,
I guess when I add the form for instant I will have to add the other form something like this:

elseif(!isset($_POST['enviar']) or !isset($_POST['enviar3'])){



Thanks a lot, how things not that complicated can look complicated....

helenp




msg:4522611
 4:52 pm on Nov 26, 2012 (gmt 0)

Already tried to add, and for both this is the correct:
elseif(!isset($_POST['enviarenquirer']) and !isset($_POST['enviarinstant']))
{
Thanks again

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved