Jump to content

[SOLVED] How to direct the current page to another page ?


Recommended Posts

Thanks for your prompt reply!

 

No.  What I meant is that once users click the form submit button, the current page should automatically be directed to another page that shows the users' input (because most users don't want to see the same page again with an empty form).  Is there a PHP function that I can pass in a URL for this purpose ?  Thanks.

 

 

form.html/form.php

<form action="URL.php" method="POST">
<input type="text" name="text">
<input type="Submit" name="submit">
</form>

 

URL.php

<?
$text = $_POST['text'];

echo "$text";
?>

That will echo what was inputted into the form field

Yeah, just remember to put the action attribute into your <form> tag.  Whatever action equals is where the page is headed with the data.  If you want to send data, you also need to include the method attribute. This will be GET or POST.  You can google the difference.

 

It looks like you already know how to write forms.  Just make sure everything has a name attribute (which will be the index in the  $_POST or $_GET array in the next page.)

 

Good luck!

But my "action" attribute already contains the link of the current page, the page from which the data is read (and write to the database).  In fact, I have set: action="some_other_link" and yes, it worked, it did direct the current page to the specified page.  However, in doing so, it fails to record the values that users enter.  Any other alternative?

Without seeing all your code, I assume you are posting the fields back to the same page and you have an if clause that checks to see if the form was submitted and puts it into the database? And now you want to send them to another page after the info is inserted?  If that is the case, after you do your inserts, you can use the header function to send them somewhere else...BUT, you will have to move all that part of the code to the beginning of the file to avoid headers already sent errors.

 

header("Location: http://yourdomain.com/yourredirect.php");

Yeah, that's what I'm talking about.  Actually, before posting for help on this forum, I had found this header function in my PHP reference book but I was skeptical about it since I wanted to direct the whole page, not just the header.  Now, since you "calabiyau" suggested this header function again, I went ahead and tried and yes, it worked successfully.  Thank you very much!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.