#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0

    Troubble nesting several "pages" on the same page


    Hi,
    As I cant pass the vars by post using headers, then I am trying to have all the information on the same page.
    I have a page when they land on it a form is displayed to choose between 2 radiobuttons. With php I check if one if them is checked, if none is checked an error message is displayed.
    If some of them is checked then another content will be displayed depending on button choosen.
    This is the landing page in wich I have not included yet the content for the radiobuttons, only an echo to check that it works, and this works perfect:

    PHP Code:
    <?php   if ($_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 enquirer }//else
     }//if enviar2
     else {?> Text with form enviar2 here}


    Then If they chekc button enquirer I want to display another form wich is a contact form. This form on a separat page works perfect, however when I try to add it inside the { } in this code: if ($bookingway=="enquirer"){ echo "enquirer"; }//if enquirer it does not send any email and dont give me the ok message, it just refresh the page and shows me the form for the landing content.
    This is what I try to add into the if ($bookingway=="enquirer"){ echo "enquirer"; }//if enquirer:

    PHP Code:
    <?php      if ($_POST['enviar']) {  
    if (!empty($_POST['name']) && !empty($_POST['tel'])  && !empty($_POST['country']) && !empty($_POST['email']) && !empty($_POST['repeat_email'])  && !empty($_POST['repeat_email']) && $_POST['email'] == $_POST['repeat_email'])
     {  $comments = str_replace("\\r\\n", " ", $comments);  require("includes/class.phpmailer.php");  información mail etc......  echo "form has been sent"; 
     if(!$mail->Send()) 
     {echo "Message could not be sent, enter a valid e-mail. <p>";     echo "Mailer Error: " . $mail->ErrorInfo;     exit;
    } 
     }//if not empty  
    else { 
    echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p class='red'>Something went wrong<br>You must fill in full name, telephone, country, valid email and repeat email to submit this form and email and repeat email must be equal.</p>";
    } 
     }//if enviar?>  
    <table width="550px" align="center" border="0" cellpadding="0" cellspacing="0">  Here comes the form and ends: <p align="center"><input type="submit" name="enviar" value="Submit" id="submit" class="submit">


    I been trying and starring to this....
    Isn´t it possible to have a form inside another statement with a form, or is something else wrong?
    Thanks,
    Last edited by helenp; November 26th, 2012 at 04:43 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Sorry, just dont get how to have it on several lines....
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    Originally Posted by helenp
    Sorry, just dont get how to have it on several lines....
    Edit your post, select the code between the [php] tags, and paste directly into the text box. Don't use the popup dialog to enter code.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Originally Posted by requinix
    Edit your post, select the code between the [php] tags, and paste directly into the text box. Don't use the popup dialog to enter code.
    Thanks, I done now but it should have the [php]tags....
    I managed to do manually starting with [highlight="PHP"] and ending with /[highlight]
    However don´t understand how to use the buttons.....guess I´m stupid.
    Last edited by helenp; November 26th, 2012 at 04:44 AM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    It looks like one cant nest 2 if ($_POST

    I done an easy form and I get the same result, instead of getting the ok from the echo, I get the echo for the landing content:

    PHP Code:
    <?php 
     if ($_POST['send2']) {	 
    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 ($_POST['send']) 
    {	echo "OK"; }
    ?><form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post" name="bookingways" id="bookingways">
    <p align="center"><input class="boton" type="submit" name="send" value="Send"> </p>
    </form> 
    <?php }//if enquirer
    }//else
    }//if send2
    else {?>
    landing content here with form: name send2
    }
    Last edited by helenp; November 26th, 2012 at 05:05 AM.
  10. #6
  11. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,548
    Rep Power
    2337
    send2 and send are not the same variable you know (and you probably do, I think I misread the problem). And you should be using isset() on the $_POST variables.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    Originally Posted by ptr2void
    send2 and send are not the same variable you know (and you probably do, I think I misread the problem). And you should be using isset() on the $_POST variables.
    Uups, sorry, no the name of the forms are ok, I just changed from spanish to english for easier understanding, fixed it now. There are 2 forms.
    What do you measn with isset, something like:
    if (isset($_POST['enviar2'])) {
    ?
    This does not work either so I have it wrong
    Thanks
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    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'])) {
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Marbella, Spain
    Posts
    381
    Rep Power
    0
    It works now, changig the else to an elsif like this:
    elseif(!isset($_POST['enviar'])) {

IMN logo majestic logo threadwatch logo seochat tools logo