By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

-> How to read a form variable before posting? <-

P: n/a
Hi,
is there a way to read the content of a form variable before
a POST?

I have a form with a "duplicate" button which opens a new form
with most of the fields filled with the values of the calling one.
To do so, I pass the id of the form to be duplicated.
Example:
- I have a form with "Number = 1234567" in a "numform" edit field.
- Duplicate has a href=/duplicateform.php?id=1234567
- then the "duplicateform.php" reads id with a GET['id']

This is easy as I come from a displayed form that retrieves its
values via a SQL statement and with a specific "number" reference.

Now, once I am in this new form, I have a save button to save all
values, including the new "Number" the user would type in, say
"22222222". The save process works correctly via AJAX and saves the
record using a POST action.
But then, I still have my "duplicate" button which should now
point to href=/duplicateform.php?id=22222222
How can I get this 22222222 value from within the form itself?
I have to get it from the "numform" field, but how can I do this?

it would be something like
href=/duplicateform.php?id=<?=[value_of_field_number]?>

with value_of_field_number being the actual value of that edit field.

Any help would be appreciated.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
As a complement to my question...

I have a hidden form field called "recid" with id="recid".

By default it's set to "-1" to let me know the form is new
and has not been stored in the database.

I was thinking about adding a javascript event to the field's
onBlur() event like:
getElementById("recid").value = getElementById("number").value

to store the value currently in my field.

Then I could use a reference like

<A href="/formduplicate.php?id=<?=$_GET['recid']?>">...</a>

But I'm afraid that this would not work as the recid variable was not
part of a POST event or passed as an URL argument.

Is this correct?
Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #2

P: n/a
How can I get this 22222222 value from within the form itself?
I have to get it from the "numform" field, but how can I do this?
Hi, check out mysql_insert_id()

--
Arjen
http://www.hondenpage.com - mijn site over honden
May 14 '07 #3

P: n/a
Actually, the following code sample works ok to built
the href tag dynamically...

<script language="javascript" type="text/javascript">
function toto() {
var num = document.getElementById("num") ;
var ref=document.getElementById("theref") ;
ref.href="mypage.php?id="+num.value ;
}
</script>

<form method="post">
<INPUT name="num" type="text" id="num" onBlur="toto();">
<A href="" id="theref">go</a>
</form>

When I click on "go" the link is correct and point to mypage
with the id= to the value I have in the edit field.

This allows me to know where to point to before POSTING. That's
what I need.
Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #4

P: n/a
On May 14, 2:56 pm, Steve JORDI <steveK_I_L_LSPAMjo...@hotmail.com>
wrote:
Actually, the following code sample works ok to built
the href tag dynamically...

<script language="javascript" type="text/javascript">
function toto() {
var num = document.getElementById("num") ;
var ref=document.getElementById("theref") ;
ref.href="mypage.php?id="+num.value ;
}
</script>

<form method="post">
<INPUT name="num" type="text" id="num" onBlur="toto();">
<A href="" id="theref">go</a>
</form>

When I click on "go" the link is correct and point to mypage
with the id= to the value I have in the edit field.

This allows me to know where to point to before POSTING. That's
what I need.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: stevejordiK_I_L_LS...@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
of course you could just post to mypage, and use
$_GET['id'] = $_POST['numform']; //with filtering of course!
if you REALLY need to populate the GET array.

May 14 '07 #5

P: n/a
I actually need to know the id of my record BEFORE
posting, so I can dynamically create the <A href>
link with the correct value passed to the mypage file.

So my javascript function does exactly what I need.

Thanks anyway.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #6

P: n/a
On May 14, 3:10 pm, Steve JORDI <steveK_I_L_LSPAMjo...@hotmail.com>
wrote:
I actually need to know the id of my record BEFORE
posting, so I can dynamically create the <A href>
link with the correct value passed to the mypage file.

So my javascript function does exactly what I need.

Thanks anyway.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: stevejordiK_I_L_LS...@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
if you say so

May 14 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.