How to POST a href link with isset
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
|
show 14 more comments
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
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 anid
attribute with valuequiz
. It would also not include thesubmit-test
parameter
– Phil
Nov 12 '18 at 0:25
|
show 14 more comments
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
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
php session post href isset
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 anid
attribute with valuequiz
. It would also not include thesubmit-test
parameter
– Phil
Nov 12 '18 at 0:25
|
show 14 more comments
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 anid
attribute with valuequiz
. It would also not include thesubmit-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
|
show 14 more comments
2 Answers
2
active
oldest
votes
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"
add a comment |
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>
One problem with this... This won't send thesubmit-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 indexsubmit-test
exists instead oftest1
, 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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"
add a comment |
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"
add a comment |
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"
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"
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>
edited Nov 12 '18 at 0:40
answered Nov 12 '18 at 0:34
PhilPhil
97.4k11140160
97.4k11140160
add a comment |
add a comment |
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>
One problem with this... This won't send thesubmit-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 indexsubmit-test
exists instead oftest1
, 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
add a comment |
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>
One problem with this... This won't send thesubmit-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 indexsubmit-test
exists instead oftest1
, 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
add a comment |
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>
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>
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 thesubmit-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 indexsubmit-test
exists instead oftest1
, 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
add a comment |
One problem with this... This won't send thesubmit-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 indexsubmit-test
exists instead oftest1
, 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 valuequiz
. It would also not include thesubmit-test
parameter– Phil
Nov 12 '18 at 0:25