473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can you _POST variables in php without using a <FORM>

Hi fairly new to php, but picking it up quite well.
the question I have, is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form which captures login_id and password which are
posted to verify.php

verify.php checks the id and password against the database.
if the check succeeds I use $_SESSION to track the logged in user into
the page.
if the check fails, I use $_SESSION["error"] to set an error message
and then jump to login.htm, but I've lost the userid.
The only way I can see of transferring the userid (and some other data)
is by calling header ("Location: login.htm?id=$uid");
and then have some php code in login.htm to $GET['uid'] and pop that
into the user field on the form.

Is there any easy way I can post this data back without using a <FORM>
or at least a form that can be auto-submitted?

Thanks in advance.

Jan 20 '06 #1
8 3514
ch**************@hotmail.com wrote:
Hi fairly new to php, but picking it up quite well.
the question I have, is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

yes its a VFAQ. learn how to use Google.

But you can't POST on a redirect - HTTP does not allow.
i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form

<snip>

So what's wrong with passing it in a GET?

C.
Jan 20 '06 #2
I tied using Gogle, either I'm not being specific enough in my question
search or too specific,
so I get hits for the normal processing of variables passed in using
POST, but nothing on how to POST back from within php.

if you could give me a link to such a site, that woud be appreciated.

yes, I could use get, and at the moment its just the userid, but the
login page may be expanded to have several fields, which is why I would
not want to paste all the variables/data into the url when sending
back.

Chris

Jan 20 '06 #3
Al
ch**************@hotmail.com wrote:
I tied using Gogle, either I'm not being specific enough in my question
search or too specific,
so I get hits for the normal processing of variables passed in using
POST, but nothing on how to POST back from within php.

if you could give me a link to such a site, that woud be appreciated.

yes, I could use get, and at the moment its just the userid, but the
login page may be expanded to have several fields, which is why I would
not want to paste all the variables/data into the url when sending
back.

Chris


You could try cookies?
Or you could have verify and login to be the same php page... then you
can set the values in the form youself.

If you still wanted them to have separate names they could both just
require("login/verify.php"); or something. Boths ways are good if you
want to avoid GETs, although I think the second works more nicely.
Cookies probably shouldn't be used for this purpose...

Jan 20 '06 #4
ch**************@hotmail.com wrote:
is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form which captures login_id and password which are
posted to verify.php

verify.php checks the id and password against the database.
if the check succeeds I use $_SESSION to track the logged in user into
the page.
if the check fails, I use $_SESSION["error"] to set an error message
and then jump to login.htm, but I've lost the userid.
use $_SESSION to save the userid and the error message

<?php
if ($check_failed) {
$_SESSION["error"] = "Check failed. Please try again.";
$_SESSION["userid"] = $userid;
}
?>
The only way I can see of transferring the userid (and some other data)
is by calling header ("Location: login.htm?id=$uid");
and then have some php code in login.htm to $GET['uid'] and pop that
into the user field on the form.

Is there any easy way I can post this data back without using a <FORM>
or at least a form that can be auto-submitted?


With the $_SESSION array.

If your web server isn't set up to call PHP for htm pages (it shouldn't)
change your login.htm to login.php first.

The first time a user calls login.php, $_SESSION is empty.
After a login failure $_SESSION has the error message *and* the userid

<?php // login.php
if (isset($_SESSION["error"])) {
echo '<p class="error">', $_SESSION["error"], '</p>';
}

// ...

echo '<input type="text" name="userid"';
if (isset($_SESSION["userid"])) {
echo ' value="', $_SESSION["userid"], '"';
}
echo '/>';
?>

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Jan 20 '06 #5
YES! thank you Pedro.

It works perfectly, I use sessions to keep track of users who are
logged in,
it just never occurred to me to use it for anything like passing data
back and forth between scripts.

'Duh' - One of those Homer Simpson moments.

Mucha appreciated

Chris

Jan 21 '06 #6
ch**************@hotmail.com wrote:
YES! thank you Pedro.

It works perfectly, I use sessions to keep track of users who are
logged in,
it just never occurred to me to use it for anything like passing data
back and forth between scripts.

'Duh' - One of those Homer Simpson moments.

Mucha appreciated

Chris


That's what it's BEST at!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 21 '06 #7
the browser, if I am correct, feeds the variables over the HTTP port like a
terminal, and are read in STDIN like it was coming in from a keyboard. but
I am not sure how they are serialized.

you can use javascript to autosubmit the form.
document.forms[0].submit();

<ch**************@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi fairly new to php, but picking it up quite well.
the question I have, is it possible for a php script which is used to
validate values submitted in a form, to then post these values onto
another script/page or even back to the calling form?

i.e. the application I have in question is a login.htm page with a
verify.php script
The login.htm has a Form which captures login_id and password which are
posted to verify.php

verify.php checks the id and password against the database.
if the check succeeds I use $_SESSION to track the logged in user into
the page.
if the check fails, I use $_SESSION["error"] to set an error message
and then jump to login.htm, but I've lost the userid.
The only way I can see of transferring the userid (and some other data)
is by calling header ("Location: login.htm?id=$uid");
and then have some php code in login.htm to $GET['uid'] and pop that
into the user field on the form.

Is there any easy way I can post this data back without using a <FORM>
or at least a form that can be auto-submitted?

Thanks in advance.

Jan 24 '06 #8
Although probably not very efficient, you may want to look at fsockopen
(http://us2.php.net/manual/en/function.fsockopen.php), which would
allow to connect to your web server with a POST request. I, however,
would use sessions.

Jan 25 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keiron Waites | last post by:
I have the following code: <input type="text" name="search" class="search_top"> <a href="" onclick="window.location='search.inc.php'+document..search. value; return false;"...
6
by: Don | last post by:
I'm trying to come up with a way within a client-side web page of uploading a couple files to a server-side PHP program without using a <form...>. I don't want to give up the page which happens...
3
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input...
4
by: Howard Jess | last post by:
In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865), my form disappears from the HTML markup (below). To summarize: 1) In a <script> block in the <head> I create a form...
6
by: snacktime | last post by:
I've searched and searched and have not found a solution to suppress the margin on form or href tags so that there is no space before or after the tag. The only way I have found to do this is to...
4
by: rob c | last post by:
This is a minor thing and only appears in IE (so far), but I'd like to know to correct it (if possible). Whenever I use a form on a webpage, Explorer always leaves a blank line following the...
19
by: Coward 9 | last post by:
HI, I saw in an example hello.aspx, there is a <form tagbeing used like <form runat="server> I search all html tag references and could NOT find "runat" attributes for <formtag. which...
5
by: shotokan99 | last post by:
for instance i do have this element but i dont have a <form>: <input type="Text" name="myname" id="myname" size="30"...> then i have this link: echo'<a...
10
by: neverquit | last post by:
hi , Iam Nagesh,Begineer in using Ajax,well i have been using ajax in application, i have faced a problem while placing the responseTEXT into the <div> tag positioned inside the <form> tag iam...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.