How to POST a href link with isset










-3















Please help me, I wanted to do a post method using an anchor tag.
Here is the sample code:



<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
<a href="essay2.php" name="submit-test">2</a>
</li>
</ul>
<input type="text" name="test1">
</form>


And the PHP code:



<?php
session_start();

if (isset($_POST['submit-test']))
$_SESSION['test1'] = $_POST['test1'];
header("Location: essay2.php"]);

?>









share|improve this question



















  • 1





    sidenote: the header redirect after the echo won't work.

    – Jeff
    Nov 12 '18 at 0:15






  • 1





    they edited @Jeff and Phil did a rollback just now. I wonder how many more edits this will go through lol! There's been 6 now.

    – Funk Forty Niner
    Nov 12 '18 at 0:17







  • 1





    an anchor tag <a> won't send anything with a form. So $_POST['submit-test'] will never be set. Again (as Funk said): what's the usecase for this?

    – Jeff
    Nov 12 '18 at 0:18







  • 1





    You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link. See Bootstrap's link button for an example. I'd give that a try if this is purely for the UI. Otherwise, you'll need to involve some JS to have an anchor submit a form

    – Phil
    Nov 12 '18 at 0:19







  • 1





    That's because your form doesn't have an id attribute with value quiz. It would also not include the submit-test parameter

    – Phil
    Nov 12 '18 at 0:25
















-3















Please help me, I wanted to do a post method using an anchor tag.
Here is the sample code:



<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
<a href="essay2.php" name="submit-test">2</a>
</li>
</ul>
<input type="text" name="test1">
</form>


And the PHP code:



<?php
session_start();

if (isset($_POST['submit-test']))
$_SESSION['test1'] = $_POST['test1'];
header("Location: essay2.php"]);

?>









share|improve this question



















  • 1





    sidenote: the header redirect after the echo won't work.

    – Jeff
    Nov 12 '18 at 0:15






  • 1





    they edited @Jeff and Phil did a rollback just now. I wonder how many more edits this will go through lol! There's been 6 now.

    – Funk Forty Niner
    Nov 12 '18 at 0:17







  • 1





    an anchor tag <a> won't send anything with a form. So $_POST['submit-test'] will never be set. Again (as Funk said): what's the usecase for this?

    – Jeff
    Nov 12 '18 at 0:18







  • 1





    You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link. See Bootstrap's link button for an example. I'd give that a try if this is purely for the UI. Otherwise, you'll need to involve some JS to have an anchor submit a form

    – Phil
    Nov 12 '18 at 0:19







  • 1





    That's because your form doesn't have an id attribute with value quiz. It would also not include the submit-test parameter

    – Phil
    Nov 12 '18 at 0:25














-3












-3








-3








Please help me, I wanted to do a post method using an anchor tag.
Here is the sample code:



<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
<a href="essay2.php" name="submit-test">2</a>
</li>
</ul>
<input type="text" name="test1">
</form>


And the PHP code:



<?php
session_start();

if (isset($_POST['submit-test']))
$_SESSION['test1'] = $_POST['test1'];
header("Location: essay2.php"]);

?>









share|improve this question
















Please help me, I wanted to do a post method using an anchor tag.
Here is the sample code:



<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
<a href="essay2.php" name="submit-test">2</a>
</li>
</ul>
<input type="text" name="test1">
</form>


And the PHP code:



<?php
session_start();

if (isset($_POST['submit-test']))
$_SESSION['test1'] = $_POST['test1'];
header("Location: essay2.php"]);

?>






php session post href isset






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 0:35







Carlo Montemayor

















asked Nov 12 '18 at 0:12









Carlo MontemayorCarlo Montemayor

21




21







  • 1





    sidenote: the header redirect after the echo won't work.

    – Jeff
    Nov 12 '18 at 0:15






  • 1





    they edited @Jeff and Phil did a rollback just now. I wonder how many more edits this will go through lol! There's been 6 now.

    – Funk Forty Niner
    Nov 12 '18 at 0:17







  • 1





    an anchor tag <a> won't send anything with a form. So $_POST['submit-test'] will never be set. Again (as Funk said): what's the usecase for this?

    – Jeff
    Nov 12 '18 at 0:18







  • 1





    You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link. See Bootstrap's link button for an example. I'd give that a try if this is purely for the UI. Otherwise, you'll need to involve some JS to have an anchor submit a form

    – Phil
    Nov 12 '18 at 0:19







  • 1





    That's because your form doesn't have an id attribute with value quiz. It would also not include the submit-test parameter

    – Phil
    Nov 12 '18 at 0:25













  • 1





    sidenote: the header redirect after the echo won't work.

    – Jeff
    Nov 12 '18 at 0:15






  • 1





    they edited @Jeff and Phil did a rollback just now. I wonder how many more edits this will go through lol! There's been 6 now.

    – Funk Forty Niner
    Nov 12 '18 at 0:17







  • 1





    an anchor tag <a> won't send anything with a form. So $_POST['submit-test'] will never be set. Again (as Funk said): what's the usecase for this?

    – Jeff
    Nov 12 '18 at 0:18







  • 1





    You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link. See Bootstrap's link button for an example. I'd give that a try if this is purely for the UI. Otherwise, you'll need to involve some JS to have an anchor submit a form

    – Phil
    Nov 12 '18 at 0:19







  • 1





    That's because your form doesn't have an id attribute with value quiz. It would also not include the submit-test parameter

    – Phil
    Nov 12 '18 at 0:25








1




1





sidenote: the header redirect after the echo won't work.

– Jeff
Nov 12 '18 at 0:15





sidenote: the header redirect after the echo won't work.

– Jeff
Nov 12 '18 at 0:15




1




1





they edited @Jeff and Phil did a rollback just now. I wonder how many more edits this will go through lol! There's been 6 now.

– Funk Forty Niner
Nov 12 '18 at 0:17






they edited @Jeff and Phil did a rollback just now. I wonder how many more edits this will go through lol! There's been 6 now.

– Funk Forty Niner
Nov 12 '18 at 0:17





1




1





an anchor tag <a> won't send anything with a form. So $_POST['submit-test'] will never be set. Again (as Funk said): what's the usecase for this?

– Jeff
Nov 12 '18 at 0:18






an anchor tag <a> won't send anything with a form. So $_POST['submit-test'] will never be set. Again (as Funk said): what's the usecase for this?

– Jeff
Nov 12 '18 at 0:18





1




1





You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link. See Bootstrap's link button for an example. I'd give that a try if this is purely for the UI. Otherwise, you'll need to involve some JS to have an anchor submit a form

– Phil
Nov 12 '18 at 0:19






You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link. See Bootstrap's link button for an example. I'd give that a try if this is purely for the UI. Otherwise, you'll need to involve some JS to have an anchor submit a form

– Phil
Nov 12 '18 at 0:19





1




1





That's because your form doesn't have an id attribute with value quiz. It would also not include the submit-test parameter

– Phil
Nov 12 '18 at 0:25






That's because your form doesn't have an id attribute with value quiz. It would also not include the submit-test parameter

– Phil
Nov 12 '18 at 0:25













2 Answers
2






active

oldest

votes


















0














To elaborate on my comment above...




You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link




consider this approach






button[name="submit-test"] 
background: transparent;
border: 0 none;
color: blue;
text-decoration: underline;
font: inherit;
cursor: pointer;

<form action="essay2.php" id="quiz" name="quiz" method="post">
<ul>
<li>
<button name="submit-test" type="submit">2</button>
</li>
</ul>
<input type="text" name="test1">
</form>





Results in the following sent when you click the "2"



Network console






share|improve this answer
































    0














    You can use javascript with the onclick method on your link.



    <a href="#" onclick="document.getElementById('myform').submit();">click to send</a>


    You also need to put a id to your form tag (id="myform" in this case).



    This is how I would do:



    <form action="essay2.php" id="quiz" name="quiz" method="post">
    <ul>
    <li>
    <a href="#" onclick="document.getElementById('quiz').submit();">2</a>
    </li>
    </ul>
    <input type="text" name="test1">
    <input type="hidden" name="submit-test">
    </form>





    share|improve this answer

























    • One problem with this... This won't send the submit-test parameter which OP's PHP relies on

      – Phil
      Nov 12 '18 at 0:27












    • Thanks for that, But I want to pass the $_POST['test1'] to $_SESSION['test1'] using the POST method.

      – Carlo Montemayor
      Nov 12 '18 at 0:28











    • @CarloMontemayor this will most certainly do that

      – Phil
      Nov 12 '18 at 0:29











    • Not really since it's testing if the index submit-test exists instead of test1, which makes no sense. That has to be fixed too.

      – Havenard
      Nov 12 '18 at 0:30






    • 2





      if you want to pass the submit-test parameter, just add a hidden input named submit-test to the form

      – dAm2K
      Nov 12 '18 at 0:30










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254523%2fhow-to-post-a-href-link-with-isset%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    To elaborate on my comment above...




    You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link




    consider this approach






    button[name="submit-test"] 
    background: transparent;
    border: 0 none;
    color: blue;
    text-decoration: underline;
    font: inherit;
    cursor: pointer;

    <form action="essay2.php" id="quiz" name="quiz" method="post">
    <ul>
    <li>
    <button name="submit-test" type="submit">2</button>
    </li>
    </ul>
    <input type="text" name="test1">
    </form>





    Results in the following sent when you click the "2"



    Network console






    share|improve this answer





























      0














      To elaborate on my comment above...




      You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link




      consider this approach






      button[name="submit-test"] 
      background: transparent;
      border: 0 none;
      color: blue;
      text-decoration: underline;
      font: inherit;
      cursor: pointer;

      <form action="essay2.php" id="quiz" name="quiz" method="post">
      <ul>
      <li>
      <button name="submit-test" type="submit">2</button>
      </li>
      </ul>
      <input type="text" name="test1">
      </form>





      Results in the following sent when you click the "2"



      Network console






      share|improve this answer



























        0












        0








        0







        To elaborate on my comment above...




        You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link




        consider this approach






        button[name="submit-test"] 
        background: transparent;
        border: 0 none;
        color: blue;
        text-decoration: underline;
        font: inherit;
        cursor: pointer;

        <form action="essay2.php" id="quiz" name="quiz" method="post">
        <ul>
        <li>
        <button name="submit-test" type="submit">2</button>
        </li>
        </ul>
        <input type="text" name="test1">
        </form>





        Results in the following sent when you click the "2"



        Network console






        share|improve this answer















        To elaborate on my comment above...




        You can actually style a <button type="submit" name="submit-test">2</button> element to look exactly like a plain text link




        consider this approach






        button[name="submit-test"] 
        background: transparent;
        border: 0 none;
        color: blue;
        text-decoration: underline;
        font: inherit;
        cursor: pointer;

        <form action="essay2.php" id="quiz" name="quiz" method="post">
        <ul>
        <li>
        <button name="submit-test" type="submit">2</button>
        </li>
        </ul>
        <input type="text" name="test1">
        </form>





        Results in the following sent when you click the "2"



        Network console






        button[name="submit-test"] 
        background: transparent;
        border: 0 none;
        color: blue;
        text-decoration: underline;
        font: inherit;
        cursor: pointer;

        <form action="essay2.php" id="quiz" name="quiz" method="post">
        <ul>
        <li>
        <button name="submit-test" type="submit">2</button>
        </li>
        </ul>
        <input type="text" name="test1">
        </form>





        button[name="submit-test"] 
        background: transparent;
        border: 0 none;
        color: blue;
        text-decoration: underline;
        font: inherit;
        cursor: pointer;

        <form action="essay2.php" id="quiz" name="quiz" method="post">
        <ul>
        <li>
        <button name="submit-test" type="submit">2</button>
        </li>
        </ul>
        <input type="text" name="test1">
        </form>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 '18 at 0:40

























        answered Nov 12 '18 at 0:34









        PhilPhil

        97.4k11140160




        97.4k11140160























            0














            You can use javascript with the onclick method on your link.



            <a href="#" onclick="document.getElementById('myform').submit();">click to send</a>


            You also need to put a id to your form tag (id="myform" in this case).



            This is how I would do:



            <form action="essay2.php" id="quiz" name="quiz" method="post">
            <ul>
            <li>
            <a href="#" onclick="document.getElementById('quiz').submit();">2</a>
            </li>
            </ul>
            <input type="text" name="test1">
            <input type="hidden" name="submit-test">
            </form>





            share|improve this answer

























            • One problem with this... This won't send the submit-test parameter which OP's PHP relies on

              – Phil
              Nov 12 '18 at 0:27












            • Thanks for that, But I want to pass the $_POST['test1'] to $_SESSION['test1'] using the POST method.

              – Carlo Montemayor
              Nov 12 '18 at 0:28











            • @CarloMontemayor this will most certainly do that

              – Phil
              Nov 12 '18 at 0:29











            • Not really since it's testing if the index submit-test exists instead of test1, which makes no sense. That has to be fixed too.

              – Havenard
              Nov 12 '18 at 0:30






            • 2





              if you want to pass the submit-test parameter, just add a hidden input named submit-test to the form

              – dAm2K
              Nov 12 '18 at 0:30















            0














            You can use javascript with the onclick method on your link.



            <a href="#" onclick="document.getElementById('myform').submit();">click to send</a>


            You also need to put a id to your form tag (id="myform" in this case).



            This is how I would do:



            <form action="essay2.php" id="quiz" name="quiz" method="post">
            <ul>
            <li>
            <a href="#" onclick="document.getElementById('quiz').submit();">2</a>
            </li>
            </ul>
            <input type="text" name="test1">
            <input type="hidden" name="submit-test">
            </form>





            share|improve this answer

























            • One problem with this... This won't send the submit-test parameter which OP's PHP relies on

              – Phil
              Nov 12 '18 at 0:27












            • Thanks for that, But I want to pass the $_POST['test1'] to $_SESSION['test1'] using the POST method.

              – Carlo Montemayor
              Nov 12 '18 at 0:28











            • @CarloMontemayor this will most certainly do that

              – Phil
              Nov 12 '18 at 0:29











            • Not really since it's testing if the index submit-test exists instead of test1, which makes no sense. That has to be fixed too.

              – Havenard
              Nov 12 '18 at 0:30






            • 2





              if you want to pass the submit-test parameter, just add a hidden input named submit-test to the form

              – dAm2K
              Nov 12 '18 at 0:30













            0












            0








            0







            You can use javascript with the onclick method on your link.



            <a href="#" onclick="document.getElementById('myform').submit();">click to send</a>


            You also need to put a id to your form tag (id="myform" in this case).



            This is how I would do:



            <form action="essay2.php" id="quiz" name="quiz" method="post">
            <ul>
            <li>
            <a href="#" onclick="document.getElementById('quiz').submit();">2</a>
            </li>
            </ul>
            <input type="text" name="test1">
            <input type="hidden" name="submit-test">
            </form>





            share|improve this answer















            You can use javascript with the onclick method on your link.



            <a href="#" onclick="document.getElementById('myform').submit();">click to send</a>


            You also need to put a id to your form tag (id="myform" in this case).



            This is how I would do:



            <form action="essay2.php" id="quiz" name="quiz" method="post">
            <ul>
            <li>
            <a href="#" onclick="document.getElementById('quiz').submit();">2</a>
            </li>
            </ul>
            <input type="text" name="test1">
            <input type="hidden" name="submit-test">
            </form>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 12 '18 at 0:41

























            answered Nov 12 '18 at 0:26









            dAm2KdAm2K

            7,90843039




            7,90843039












            • One problem with this... This won't send the submit-test parameter which OP's PHP relies on

              – Phil
              Nov 12 '18 at 0:27












            • Thanks for that, But I want to pass the $_POST['test1'] to $_SESSION['test1'] using the POST method.

              – Carlo Montemayor
              Nov 12 '18 at 0:28











            • @CarloMontemayor this will most certainly do that

              – Phil
              Nov 12 '18 at 0:29











            • Not really since it's testing if the index submit-test exists instead of test1, which makes no sense. That has to be fixed too.

              – Havenard
              Nov 12 '18 at 0:30






            • 2





              if you want to pass the submit-test parameter, just add a hidden input named submit-test to the form

              – dAm2K
              Nov 12 '18 at 0:30

















            • One problem with this... This won't send the submit-test parameter which OP's PHP relies on

              – Phil
              Nov 12 '18 at 0:27












            • Thanks for that, But I want to pass the $_POST['test1'] to $_SESSION['test1'] using the POST method.

              – Carlo Montemayor
              Nov 12 '18 at 0:28











            • @CarloMontemayor this will most certainly do that

              – Phil
              Nov 12 '18 at 0:29











            • Not really since it's testing if the index submit-test exists instead of test1, which makes no sense. That has to be fixed too.

              – Havenard
              Nov 12 '18 at 0:30






            • 2





              if you want to pass the submit-test parameter, just add a hidden input named submit-test to the form

              – dAm2K
              Nov 12 '18 at 0:30
















            One problem with this... This won't send the submit-test parameter which OP's PHP relies on

            – Phil
            Nov 12 '18 at 0:27






            One problem with this... This won't send the submit-test parameter which OP's PHP relies on

            – Phil
            Nov 12 '18 at 0:27














            Thanks for that, But I want to pass the $_POST['test1'] to $_SESSION['test1'] using the POST method.

            – Carlo Montemayor
            Nov 12 '18 at 0:28





            Thanks for that, But I want to pass the $_POST['test1'] to $_SESSION['test1'] using the POST method.

            – Carlo Montemayor
            Nov 12 '18 at 0:28













            @CarloMontemayor this will most certainly do that

            – Phil
            Nov 12 '18 at 0:29





            @CarloMontemayor this will most certainly do that

            – Phil
            Nov 12 '18 at 0:29













            Not really since it's testing if the index submit-test exists instead of test1, which makes no sense. That has to be fixed too.

            – Havenard
            Nov 12 '18 at 0:30





            Not really since it's testing if the index submit-test exists instead of test1, which makes no sense. That has to be fixed too.

            – Havenard
            Nov 12 '18 at 0:30




            2




            2





            if you want to pass the submit-test parameter, just add a hidden input named submit-test to the form

            – dAm2K
            Nov 12 '18 at 0:30





            if you want to pass the submit-test parameter, just add a hidden input named submit-test to the form

            – dAm2K
            Nov 12 '18 at 0:30

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254523%2fhow-to-post-a-href-link-with-isset%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế