Insert text variable into URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tashielb
Forum Newbie
Posts: 1
Joined: Fri Jan 27, 2012 2:19 pm

Insert text variable into URL

Post by Tashielb »

Hi Guys

Please forgive my ignorance, I am a newbie to HTML etc, I just want to perform a simple task but do not know where to begin.

I want to make a very simple website with different text fields, eg:

Text1 text box to enter text)
Text2 : (text box to enter text)
....

And then I want to take that entered text and insert it into a URL when the person has completed entering the text and clicks a button, eg:

Http://www.domain.com/directory?

So essentially I want the text to be injected into a URL and path followed when the button is clicked, am I making sense or do I sound like a nut?

For example, I was given an API from a Dns host, it's a URL, I want to make it easier to enter, see below
https://zonomi.com/app/dns/dyndns.jsp?a ... A&api_key=

So I want the "action" to be one of 3 buttons, set, delete, query, and dePending on which button you click after typing a text into the text field (the text entered should auto fill in the name= section.) it should insert into the URL and follow it.


So for instance, someone goes to my website, on there, there is a text box and 3 buttons, they enter "test1" into the text box and click the "set" button, this is the URL I want it to follow next:

https://zonomi.com/app/dns/dyndns.jsp?a ... A&api_key=
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Insert text variable into URL

Post by Celauran »

Use a form to capture their input, then use the header() function to redirect them.

Quick & dirty example:

Code: Select all

$url = 'https://zonomi.com/app/dns/dyndns.jsp?action=SET&name={@REPLACE}.example.com&type=A&api_key=';

if (!empty($_POST))
{
    if ($_POST['set'])
    {
        $destination = str_replace('{@REPLACE}', $_POST['foo'], $url);
        header('Location: ' . $destination);
    }
}
Post Reply