PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 18th, 2012, 04:17 PM
NSOS NSOS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 NSOS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 55 sec
Reputation Power: 0
PHP-General - Read Values from a html page

This might seem really basic to some people but I don't know how to get the $_GET or $_POST to work when the php code is on the same page as the html form. I've seen
'Form action = 'somefunc.php' but I don't want to call any outside function. I use jquery for tag clicking etc and in a small part of it I use some php where I need to base an if statement on the value of a text box but neither the $_GET or $_POST work. Is there some special way of identifying the form? Thanks in advance..

Reply With Quote
  #2  
Old October 18th, 2012, 04:54 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 29 m 55 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Before anything else, forms will submit to pages. Not to functions. The file may be named "somefunc.php" but the form will not be executing a function.

To get $_GET and $_POST the form has to be submitted to the action (ie, somefunc.php) with the accompanying page refresh or AJAX. If you're doing stuff with Javascript then, well, it depends what you're doing.

So what's your code?

Reply With Quote
  #3  
Old October 18th, 2012, 05:17 PM
NSOS NSOS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 NSOS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 55 sec
Reputation Power: 0
This is an excerpt of the code

[code]
<!DOCTYPE html>
<html>
<head>

<!-- Javascript files -->
<script type="text/javascript" src="<?php print $ThisLocation ;?>/Javascript/jquery-1.7.2.min.js"></script>

<form action="" method="post" id="admin_options_form">

<script type="text/javascript">

$(document).ready(function()
{
$("#savedata").click(function () {
$(this).hide("slow");

<?php

if ( stripslashes($_POST["clickPressed"]) == 'Yes')
{
update_option('myOption1',
stripslashes($_POST['option1']) );

update_option('myOption2',
stripslashes($_POST['option2']) );

update_option('myOption3',
stripslashes($_POST['option3']) );
}
?>

});
});
</script>

</head>
<body>

.....html text boxes etc

The above $_POST's return a blank even though the values are there. I 'include this form in a different php function and the $_POST's work in that function. The values are read correctly there but I want them read within the form.

Reply With Quote
  #4  
Old October 18th, 2012, 05:32 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 29 m 55 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
So you're saying that
PHP Code:
 print_r($_POST); 

always shows an empty array? And the form is most definitely being submitted?

Reply With Quote
  #5  
Old October 19th, 2012, 02:09 AM
NSOS NSOS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 NSOS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 55 sec
Reputation Power: 0
ok that is probably the problem. I didn't submit the form as I didn't know I had to. I'm assuming from your reply that I need to submit for $_GET and $_POST to work.
Is there any way to read html values in that php section without submitting. I don't want to leave the page.

Thanks for the help

Reply With Quote
  #6  
Old October 19th, 2012, 02:21 AM
NSOS NSOS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 NSOS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 55 sec
Reputation Power: 0
I know I can read the html valuesin jquery but I want to access those values in the php code. Is it possible to use jquery within php like the following:

[code]

<?php

if ( "<script>$("#myOption1").text</script>" == 'Yes')
{
.....
}
?>

Reply With Quote
  #7  
Old October 19th, 2012, 02:46 AM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
Quote:
Originally Posted by NSOS
I know I can read the html valuesin jquery but I want to access those values in the php code. Is it possible to use jquery within php like the following:

[code]

<?php

if ( "<script>$("#myOption1").text</script>" == 'Yes')
{
.....
}
?>


no, php will treat that as a string, PHP as an interpretor / language does not know what javascript is.

PHP is server side, the information you are trying to read is client side, so you can't access it directly with php, you need a way of sending the data to the server so PHP can do it's thing.

You will need to do this via javascript / jquery. If you don't want the user to have to hit submit you can call a function when the user changes a field in the form.


tldr: No, you cannot access a form with only php without the user hitting submit.

-SD
__________________
"Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

Looking for a project Idea?

Reply With Quote
  #8  
Old October 19th, 2012, 03:53 AM
NSOS NSOS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 NSOS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 55 sec
Reputation Power: 0
thanks,
you wrote -- 'If you don't want the user to have to hit submit you can call a function when the user changes a field in the form.' -- can that function (which I want to write in PHP) read the info on the form? if so how?

Reply With Quote
  #9  
Old October 19th, 2012, 04:32 AM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
Quote:
Originally Posted by NSOS
thanks,
you wrote -- 'If you don't want the user to have to hit submit you can call a function when the user changes a field in the form.' -- can that function (which I want to write in PHP) read the info on the form? if so how?


you need to do some research into client side vs server side coding. I STRONGLY recommend you do that now. It will make your life a LOT easier.

PHP Cannot see the data unless it is sent to it by either a user pushing the submit button, or javascript sends it.

So the function which is called when a user updates a field in the form MUST be a client side language (basically, Javascript or JQuery). That JS function can then use AJAX to send the form data to a php script and wait for a response. That response can then be used to modify the page.

Reply With Quote
  #10  
Old October 19th, 2012, 04:41 AM
NSOS NSOS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 NSOS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 55 sec
Reputation Power: 0
thanks so much for the responses.
I know I need to do a lot more research, it's just that in the last few months I've been learning HTML, CSS, jquery, some javascript, PHP and now it looks like I better learn some AJAX too. Just wanted to get this part finished and working before I tackle more.

Reply With Quote
  #11  
Old October 19th, 2012, 05:06 AM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
depending on exactly what you are trying to achieve, it should be fairly straight forward. This should give you a good starting point: w3schools

there are plenty of other good tutorials out there too.
Comments on this post
requinix disagrees: w3fools.com

Reply With Quote
  #12  
Old October 19th, 2012, 07:03 AM
NSOS NSOS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 NSOS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 55 sec
Reputation Power: 0
thanks, yes w3schools is a great place to learn. Thanks for all your help. I really appreciate it.

Reply With Quote
  #13  
Old October 19th, 2012, 11:37 PM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
Quote:
Originally Posted by NSOS
thanks, yes w3schools is a great place to learn. Thanks for all your help. I really appreciate it.


I wouldn't say a great place to learn, but it's good for a beginner to get a taste of what they need to do.

requinex, I don't rate w3schools for indepth stuff, but for a first experience with a language they are not all bad.

Reply With Quote
  #14  
Old October 19th, 2012, 11:56 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 29 m 55 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by sir_drinxalot
I wouldn't say a great place to learn, but it's good for a beginner to get a taste of what they need to do.

requinex, I don't rate w3schools for indepth stuff, but for a first experience with a language they are not all bad.

For a glance at how things work, sure. But they offer more than that and a beginner won't know when to stop reading and start looking for more in-depth and accurate advice. PHP has enough of a problem as it is with things like magic quotes and register_globals; showing them how to echo $_GET values directly and embed POSTed values in SQL queries doesn't help.

Reply With Quote
  #15  
Old October 20th, 2012, 02:04 AM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
Quote:
Originally Posted by requinix
For a glance at how things work, sure. But they offer more than that and a beginner won't know when to stop reading and start looking for more in-depth and accurate advice. PHP has enough of a problem as it is with things like magic quotes and register_globals; showing them how to echo $_GET values directly and embed POSTed values in SQL queries doesn't help.


I fully agree, my intention was to open NSOS' mind to client vs server side and get them started on their way to using jquery to bridge that gap etc.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Read Values from a html page

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap