Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
question about what you can do with forms
Old 04-06-2010, 12:40 PM question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
*the question has been answered but is replaced with a problem*
the problem is this:
I'm sending some info to flash.php with this code

HTML Code:
<form id="form1" action="flash.php" method="get">
<input type="hidden" name="value1" id="value1" value="SOMEVALUE">
<a href="flash.php" onclick="document.getElementById('form1').submit(); return false;">Flash</a>
</form>
and im trying get that info out on the page with this:
PHP Code:
$val $_GET['value1'];
echo 
$val


I don't get any value from:" echo $val; but the info shows up in the url(since its a get form)

.../flash.php?value1=SOMEVALUE

If anyone could think of any reason why echoing the variable doesent work then please post it

----
helpers that made me get this far: nayes84 , lynxus
----

----
original post
----

hey everyone. I have a question about forms.

ive seen examples in diffrent tutorials about forms that send user input to other pages.

Code:
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
</form
in my code i'm trying to use this method on a link so i can get diffrent values

i thought i neaded to add a value to the post(since none gets inputed)

Code:
<form action="flash.php" method="post" value="flash">
 <a href="flash.php" >Flash</a>
</form>
and then i would simply get the value using $_POST

unfortunately for me it doesn't work

would really appreciate if someone could tell me what im doing wrong or if you just cant do it in the way i tried

thanks a bunch for looking
would save me a lot of work if i can get this working so please help me out

Last edited by Q_fars; 04-08-2010 at 11:32 AM..
Q_fars is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-06-2010, 01:52 PM Re: question about what you can do with forms
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
You can't send post request using anchors (link)
You can use image instead
HTML Code:
<input type="image" ... />
Or you can use javascript
HTML Code:
<form id="form1" action="flash.php" method="post">
<a href="#" onclick="document.getElementById('form1').submit();return false;">Flash</a>
</form>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 04-06-2010 at 01:54 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-06-2010, 02:57 PM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
to bad but thanks for pointing it out nayes. guess il have to go the hard way.

i think you just might have pointed out what i needed though with that second code line. il try it in a while (busy) even though i have no idea how it works.

Even though the code is named "javascript" i dont have to do anything in flash right?

sorry if you have to scale it down to the very basics but i have never heard of this before so i got no idea what its all about

thanks again for replying!
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-06-2010, 03:01 PM Re: question about what you can do with forms
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
"Even though the code is named "javascript" i dont have to do anything in flash right?"


Javascript has nothing to do with flash.

All his example here does is:
<form id="form1" action="flash.php" method="post">
<a href="#" onclick="document.getElementById('form1').submit();ret urn false;">Flash</a>
</form>

Creates a form ( so you can use the post method rather than putting vars in the url, ie: google.com?myid=Mooo )

Then, He has a Javascript event handler that runs when the user CLICKS the text..

document.GetElementByID is a function that locates the form based on its ID ( ie: form1 )

.submit means the javascript will SUBMIT the form as if a user was clicking submit.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 04-06-2010 at 03:03 PM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-06-2010, 03:26 PM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
aha!
thanks a lot lynxus and nayes!
just got back so il try it out right now but judging from lynxus explanation it should be just what i nead.

(sorry for the stupid question there but ive done a bit of coding in actionscript so i got a bit confused. just wanted to make sure)
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-06-2010, 03:34 PM Re: question about what you can do with forms
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
One thing i do find odd, is your not actually posting any information..
Your simply just sending the user to flash.php
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-06-2010, 03:54 PM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
"One thing i do find odd, is your not actually posting any information..
Your simply just sending the user to flash.php"

im not? well thats what i want to do. i tried adding a value inside the submit() box but i guess i cant do that because it didnt go well.

Code:
<form id="kflash" action="flash.php" method="post">
                            <li><a href="flash.php" onclick="document.getElementById('kflash').submit(flash);return false;">Flash</a>
basically i want to send a value together with my link

the reason is that i will have many links to the same document but the document will use the information that comes together with the link to search for data inside my database and generate it.

so if you clicked the flash link you would only get posts that were related to flash inside the database
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-06-2010, 03:58 PM Re: question about what you can do with forms
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
To put a value in ..

Do:

<form id="form1" action="flash.php" method="post">
<a href="#" onclick="document.getElementById('form1').submit();ret urn false;">Flash</a>
<input type="hidden" name="value1" id="value1" value="SOMEVALUE">
</form>


In your PHP ( if you use php )

you would have
$val = $_POST['value1'];

echo $val;

Would print:
SOMEVALUE
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 04-06-2010 at 04:01 PM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-06-2010, 05:53 PM Re: question about what you can do with forms
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
Originally Posted by lynxus View Post
"Even though the code is named "javascript" i dont have to do anything in flash right?"


Javascript has nothing to do with flash.

All his example here does is:
<form id="form1" action="flash.php" method="post">
<a href="#" onclick="document.getElementById('form1').submit();ret urn false;">Flash</a>
</form>

Creates a form ( so you can use the post method rather than putting vars in the url, ie: google.com?myid=Mooo )

Then, He has a Javascript event handler that runs when the user CLICKS the text..

document.GetElementByID is a function that locates the form based on its ID ( ie: form1 )

.submit means the javascript will SUBMIT the form as if a user was clicking submit.
Just want to make a small addition
The part
Code:
return false;
Its function is to disable the default behavior of anchor link which is to open the url specified between href="" because we added javascript functionality instead
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-07-2010, 01:24 PM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
well thanks again for the replies but its not working

i kinda raw copied your code to see if it would work (except that i changed the anchor link so i would go to the page to see the change)
HTML Code:
<form id="form1" action="flash.php" method="post">
<a href="flash.php" onclick="document.getElementById('form1').submit(); return false;">Flash</a>
<input type="hidden" name="value1" id="value1" value="SOMEVALUE">
</form>
i also used your receiver php code
PHP Code:
$val $_POST['value1'];


echo 
$val
I don't get any value from:" echo $val; "so i must be doing something wrong.
I'm viewing the page on localhost btw (shouldn't make a difference right?)

*update*
Well as I said before I don't get any value from echo but the value shows up in the url when I tried using GET.
this is how the last part of the url looks like

.../flash.php?value1=SOMEVALUE

The value is there it just doesn't print...
If anyone could think of any reason why echoing the variable doesent work then please post it - the problem is practically solved now.

Last edited by Q_fars; 04-08-2010 at 10:50 AM..
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-08-2010, 05:49 PM Re: question about what you can do with forms
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Well I copied also the two files as they are and putted them on my server and they are working
http://www.ephotobay.com/test1.html

must be something wrong with settings or whatever. do you have php installed correctly on your localhost?

or could be due to caching or some thing. try to echo more data to make browser flush them.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 04-08-2010 at 05:51 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-08-2010, 06:01 PM Re: question about what you can do with forms
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
You seem you gave me bad talkupation. lol
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-09-2010, 09:43 AM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
hmm that's probably it. i got some other php issues involving connection to databases. so it kinda makes sense (it never worked in the first place)

il google for php download but if you could give me a link that to would be great.

"You seem you gave me bad talkupation. lol"

oh snap!? I did? I meant to give you the good one(just klicked that"ad to my talkupation" button bellow your avatar) just tell me where the good button is and I'l fix it right away

the things I do. lol sorry about that
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-09-2010, 09:46 AM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
wait isn't XAMPP supposed to have php in it? well il try to just reinstall it i guess
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-09-2010, 10:11 AM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
Man... I just reinstalled XAMPP and nothing changed. there is a php directory in its file map and everything looks okay. i tried moving the files into the htdocs map (I remember from somewhere that you had to do that when you wanted to do something) guess il try an install something else and see if that works better

started up apache and mysql in the control pannel to i did yes...

Last edited by Q_fars; 04-09-2010 at 10:12 AM..
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-09-2010, 10:50 AM Re: question about what you can do with forms
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
OK, you shouldnt be getting:
flash.php?value1=SOMEVALUE

as the form method is POST so you need $_POST[' in your php script.

Another thing.

You changed the href: to flash.php.
Leave it as #

Your not using the Href anymore, as javascript is doing the work now.


<form id="form1" action="flash.php" method="post">
<a href="#" onclick="document.getElementById('form1').submit(); return false;">Flash</a>
<input type="hidden" name="value1" id="value1" value="SOMEVALUE">
</form>
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-09-2010, 11:19 AM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
well me being angry wont solve anything.

there is something odd about my file when i run it.

this is a part of the php code i use there now(the variables are correct)
PHP Code:
<?php
$val 
$_GET['value1'];
echo 
$val

//Ansluter till databasen
mysql_connect ($dbhost$dbuser$dbpass)or die("Kunde inte ansluta till databasen.<br>Felmeddelande: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());<br>

//Kör sökningen utefter vad som skickades i formuläret. <br>
...
when i run this in firefox i get this.
Code:
Felmeddelande: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error());
  //Kör sökningen utefter vad som skickades i formuläret.
I noticed that the code starts to print after the first <br> tag but doesn't actually run. (does html commands without echo in php end the php line just like a ?> would do?)
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-09-2010, 11:27 AM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
Quote:
Originally Posted by lynxus View Post
OK, you shouldnt be getting:
flash.php?value1=SOMEVALUE

as the form method is POST so you need $_POST[' in your php script.

Another thing.

You changed the href: to flash.php.
Leave it as #

Your not using the Href anymore, as javascript is doing the work now.


<form id="form1" action="flash.php" method="post">
<a href="#" onclick="document.getElementById('form1').submit(); return false;">Flash</a>
<input type="hidden" name="value1" id="value1" value="SOMEVALUE">
</form>
I changed the method to GET just so I could see if the document actually received the value. It works just the same as POST except that the value shows in the url (il edit it later but its usefull for now)

about the href part. Before i tried using "#" but i ended up on the same page(thats what it does normally). i had to link to the document to go there
Q_fars is offline
Reply With Quote
View Public Profile
 
Old 04-09-2010, 12:29 PM Re: question about what you can do with forms
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
you shouldn't put <br> in php code
PHP Code:
mysql_select_db($dbname) or die(mysql_error());<br
because it is not php keyword so it'll cause parse error
if you want to display <br> just add it as string
PHP Code:
mysql_select_db($dbname) or die(mysql_error() . '<br>'); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 04-13-2010, 01:19 PM Re: question about what you can do with forms
Novice Talker

Posts: 11
Trades: 0
yea you're right about that nayes. noticed after i got back and running. I have another computer that now has php and it works fine. no idea why it didnt work on the other one but i can finally work again and its so much easier when i can actually see when im doing something wrong =)
thanks for all the help you guys, quite the long post from something so trival.
Q_fars is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to question about what you can do with forms
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.80561 seconds with 12 queries