/    Sign up×
Community /Pin to ProfileBookmark

trying to get input value from user to add on a href link

I am Trying to submit a ID number like page ID “82871” or any page ID number
and will add this ID to the href link

example i have set the href link **http://localhost/**
add the id will need look like this **http://localhost/####**

input ID number > add to the href link > and push the button to go to the site

i have try this code but it is not working :

echo ‘<form action=”localhost/ilan” >’;
echo ‘<input name=”fname” type=”” class=”textfield” id=””]’
echo ‘<button type=”submit”>Button</button>’; echo ‘</form>’;

the code add the “?fname” between the link and ID like :

http://localhost/?fname=12345

but i need just the ID added to the url like : http://localhost/12345

thanks

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@diegotn97Oct 17.2018 — <pre>dasdasdas</pre>
Copy linkTweet thisAlerts:
@rootOct 17.2018 — [[2,3,7,54],[17,19]]
Copy linkTweet thisAlerts:
@rootOct 17.2018 — 
  • 1. in HTML a Submit button is not a &lt;button&gt; but an &lt;input&gt;

  • 2. getTING THE uRL INFORMATION IS EITHER A get OR A post variable on the server

  • 3. if you need that type of URL then that what you input from the start or if its to be out put, use an echo.
  • Copy linkTweet thisAlerts:
    @artimanauthorOct 17.2018 — @root#1596872

    it wil not output as a echo it goes as a url to the site

    but the problem still the ?fname in the midle of the url so it goes to a wrong url site

    when you push submit

    i need to get the url when you input the ID "12345" combined, so that it will be goes to the url "http://localhost/ilan/12345"
    Copy linkTweet thisAlerts:
    @SempervivumOct 17.2018 — You can do this by javascript: Listen for the submit event of the form, disable the default action (submitting the form) and call the page by document.location.href:
    &lt;form id="theform" action="localhost/ilan/" method="get"&gt;
    &lt;input name="fname" type="" class="textfield"&gt;
    &lt;input type="submit" value="Go!"&gt;
    &lt;/form&gt;
    &lt;script&gt;
    document.getElementById("theform").addEventListener("submit", function (event) {
    event.preventDefault();
    var theid = document.querySelector("input[name='fname']").value;
    document.location.href = this.action + theid;
    });
    &lt;/script&gt;

    However, when doing things this way, the form is not necessary:
    <i>
    </i> &lt;input id="fname" data-url="localhost/ilan/" class="textfield"&gt;
    &lt;button id="gobtn"&gt;Go!&lt;/button&gt;
    &lt;script&gt;
    document.getElementById("gobtn").addEventListener("click", function (event) {
    var theinput = document.getElementById("fname");
    var theurl = theinput.getAttribute("data-url");
    var theid = theinput.value;
    document.location.href = theurl + theid;
    });
    &lt;/script&gt;
    Copy linkTweet thisAlerts:
    @rootOct 18.2018 — @artiman#1596883 YOU ECHO THE OUTPUT SO YOU CAN SEE IF IT IS CORRECTLY FORMATTED or more importantly THAT IT has actually been set...

    Many people have faith in their scripting to find their overall fundamental fault was their typo and waster hours of chasing around and other peoples time by chasing down non-existent problems that was all to do with a simple failure to check an output is as it is going to be EXPECTED.

    As for the whole, I have http://mydomain.tld/somescript.ext?fname=12345

    You actually start by using http://mydomain.tld/12345 and you write your program around that structure.

    I fail to understand why people build a website then want to go throug SEO BS after all the work has been done to then do more work solving issues over SEO that should have been a design factor from the beginning.

    SEO is something you build in at the time, not an afterthought.

    IMHO you would be best off going down the .htaccess route and rewrite URL's that way, take the input of http://mydomain.tld/12345 and map it with rewrite rules to pull data from the URL http://mydomain.tld/somescript.ext?fname=12345
    Copy linkTweet thisAlerts:
    @artimanauthorOct 19.2018 — than you so much people for the help


    @Sempervivum example are the one what i was looking for

    thank you @Sempervivum
    ×

    Success!

    Help @artiman spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...