A Small PHP Question

Discussion in 'PHP' started by Nimrod EX, Oct 12, 2009.

  1. #1
    First of all, will this code work in a .php document?

    <form method="POST" action="process.php">
    	<input type="text" name="address" size="20">
    	<input type="submit" value="Submit" name="submit"><br>
    	<font face="Tahoma" size="1">Click SUBMIT to submit your information</font>
    </form>
    Code (markup):
    If so:

    How do I make it, so that when the visitors click the "Submit" button, they get redirected to a DIFFERENT PHP document? (this all has to be done in PHP, no HTML...long story).

    If that is impossible, is there any way I could make all that area change into a "Thank You" message or something?

    Again, all this has to be done in a .PHP document.
    The reason all this has to be in .php, is because this is going to be used in an application I'm developing, and the site that will use the application is the one that will be hosting it... not me. I don't have any webhosting, and the application host can't host a .html file... so I can't redirect to an html file.

    Thanks alot in advance guys <3 Sorry for the stupid question :(
     
    Nimrod EX, Oct 12, 2009 IP
  2. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #2
    Yes, it can be done in php/JS look for innerHTML.

    you can have in a .php file any type of code like:

    <script type="text/javascript">
    function changeText(){
    	document.getElementById('boldStuff').innerHTML = 'Fred Flinstone';
    }
    </script>
    
    <p>Welcome to the site <b id='boldStuff'>dude</b> </p> 
    <input type='button' onclick='changeText()' value='Change Text'/>
    PHP:
     
    astrazone, Oct 12, 2009 IP
  3. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #3
    
    <?php
    if(isset($_POST['submit']))
    {
    //process submission code...
    echo "Thank You";
    }else
    {
    ?>
    
    <form method="POST" action="process.php">
    	<input type="text" name="address" size="20">
    	<input type="submit" value="Submit" name="submit"><br>
    	<font face="Tahoma" size="1">Click SUBMIT to submit your information</font>
    </form>
    
    <?php
    
    }
    
    ?>
    
    
    Code (markup):
     
    AdnanAhsan, Oct 12, 2009 IP
  4. Arunv

    Arunv Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can't print a message "Thank you." and then redirect it.....
    If you set a action and then on submit button click you write 'thankyou' ..,But without write anything page automatic redirected...!! and in PHP code if you echo "Thankyou" and then redirect it using php code then error is ocured...so without printing you have to redirected it..

    or other wise you have to use any delay code..


    But without printing "Thank You" ...the code is..
    <?php
    if(isset($_POST['submit'])
    {
    header("location: process.php");
    }
    ?>
    <form method="POST">
    <input type="text" name="address" size="20">
    <input type="submit" value="Submit" name="submit"><br>
    <font face="Tahoma" size="1">Click SUBMIT to submit your information</font>
    </form>
     
    Arunv, Oct 12, 2009 IP
  5. Indisain

    Indisain Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    or you can used refresh method:

    <?php
    if(isset($_POST['submit']){

    print '<meta http-equiv="refresh" content="0;URL=pagename.php" />';
    exit;

    }
    ?>
     
    Indisain, Oct 12, 2009 IP
  6. Nimrod EX

    Nimrod EX Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6

    So if I add this code to AdnanAhsan's code, after they click submit, they'll be redirected to the pagename.php?
    This will have to come INSTEAD of the "Thank You" thingy right? :D

    Thanks alot guys :D you're really helping me out! and you all have great answers!
     
    Nimrod EX, Oct 13, 2009 IP
  7. Nimrod EX

    Nimrod EX Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    bump? xD

    my 2nd post hasn't been answered yet ^ ^
     
    Nimrod EX, Oct 14, 2009 IP
  8. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #8
    lol mate i wrote code just to echo thankyou, and not to redirect :p ...
    He can also print Thankyou and below new form .. just add form below echo line :)


     
    AdnanAhsan, Oct 17, 2009 IP
  9. FCM

    FCM Well-Known Member

    Messages:
    669
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    155
    #9
    Okay

    <?php
    header("Location: http://www.url.com");
    ?>

    This will redirect to the right page. You might also want to try the "sleep()" function
     
    FCM, Oct 17, 2009 IP