Click here to Skip to main content
15,511,378 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: E-mail tracking in PHP Pin
cjoki25-May-11 6:32
cjoki25-May-11 6:32 
QuestionHow to Compile a .PHP File Pin
Sajju201114-May-11 10:06
Sajju201114-May-11 10:06 
AnswerRe: How to Compile a .PHP File Pin
Luc Pattyn14-May-11 12:09
sitebuilderLuc Pattyn14-May-11 12:09 
QuestionBLDMAKE ERROR: Can't find any RVCT installation. Pin
Raj Aryan 100110-May-11 6:03
Raj Aryan 100110-May-11 6:03 
AnswerRe: BLDMAKE ERROR: Can't find any RVCT installation. Pin
Uilleam23-Jul-11 16:17
Uilleam23-Jul-11 16:17 
QuestionExecuting PHP script without leaving the page Pin
AmbiguousName3-May-11 6:03
AmbiguousName3-May-11 6:03 
AnswerRe: Executing PHP script without leaving the page Pin
enhzflep3-May-11 6:09
enhzflep3-May-11 6:09 
AnswerRe: Executing PHP script without leaving the page PinPopular
enhzflep3-May-11 7:39
enhzflep3-May-11 7:39 
Perhaps it's your lucky day!

Couldn't find the old code that I had in mind, so quickly hacked something together that should demonstrate the principle for you.
Also helped improve my own code in the process of ensuring that this code would be pretty easy to re-use. The submitForm function is fresh off my neurons and axioms - wish I'd thought of doing that when I last coded in php.

You'll need to download AjaxRequest.js - I've not included it in this post due to it's size. (AjaxRequest[^)
Though everything else you need is here.

Apologies for the total lack of error handling, and the Mickey Mouse test.php. It should however be more than enough to demonstrate my approach. I'd be interested in seeing what devoutees of jQuery think (yeah, I know it's already written, but it's about 18 times the size of code performs the functionality that I need)

=================================
File #1, index.php
=================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript" src="ajaxRequestCompressed2.js"></script>
<script type="text/javascript">

	// simply wraps document.getElementById to return a reference to the object with the id provided
	// note: Id must be unique 
	function byId(el){return document.getElementById(el)}
	
	// function that places the response to an AjaxRequest inside the specified container
	// must be a div, span or td (if my memory serves me correctly)
	function myGetAjaxResponse(target, url)
	{
	  AjaxRequest.get(
		{
		  'url':url,
		  'onSuccess':function(req){ target.innerHTML=req.responseText; }
		}
	  );
	}

	// this function will iterate through all of the elements in the specified form, adding the name
	// and value of each element to a string that is appended to the end of the php file's url
	// a fully formed url created by the call to submitForm in this example page
	// will resemble "test.php?firstName=overloaded&lastName=Name&submitMe="
	function submitForm(formIdString, targetPhpFileString, pageTgtContainerIdString)
	{
		var theForm, curItem, url;
		// get the form object
		theForm = byId(formIdString);
		// iterate through each element contained within it
		for (curItem = 0; curItem<theForm.length; curItem++)
		{	
			// if this is the first item, add the name of the php flie and a question mark
			if (curItem == 0) 
				url = targetPhpFileString + "?";
			// otherwise, just add an ampersand
			else
				url = url + "&";
			// finally, add the id and value of this element
			url = url + theForm.elements[curItem].id + "=" + theForm.elements[curItem].value;
		}
		// now that we've formed the constructed the url from the phpFile's name and the form element values,
		// lets handball the request off to the php file that will handle this request.
		myGetAjaxResponse(byId(pageTgtContainerIdString), url)
	}
	
</script>

</head>
<body>
<h1>Welcome to my  CP test!</h1>
<form id="form1" name="form1">
	<label>First Name<input id="firstName"/></label>
	<label>Last Name<input id="lastName"/></label>
	<input type=button onclick="submitForm('form1', 'test.php', 'ajaxTarget')" value="SubmitMe"/>
</form>
<div id="ajaxTarget"> </div>
</body>
</html>


=================================
File #2: test.php
=================================
<?php
	
	$firstName = $_GET["firstName"];
	$lastName = $_GET["lastName"];
	printf("%s, %s<br>", $lastName, $firstName);
?>

QuestionTo use or not to use Pin
astra.20123-May-11 1:10
astra.20123-May-11 1:10 
QuestionPHP Form help Pin
Dave McCool30-Apr-11 9:54
Dave McCool30-Apr-11 9:54 
AnswerRe: PHP Form help Pin
Peter_in_27801-May-11 5:59
professionalPeter_in_27801-May-11 5:59 
GeneralRe: PHP Form help Pin
Dave McCool1-May-11 6:08
Dave McCool1-May-11 6:08 
Questionthe apache service doesn't start Pin
Farhaneh25-Apr-11 21:10
Farhaneh25-Apr-11 21:10 
AnswerRe: the apache service doesn't start Pin
Gerben Jongerius25-Apr-11 21:41
Gerben Jongerius25-Apr-11 21:41 
QuestionAn XML printer thingy Pin
freeluna22-Apr-11 15:23
professionalfreeluna22-Apr-11 15:23 
QuestionClosing a window with button?? Pin
AmbiguousName21-Apr-11 7:00
AmbiguousName21-Apr-11 7:00 
AnswerRe: Closing a window with button?? Pin
Ali Al Omairi(Abu AlHassan)21-Apr-11 16:21
professionalAli Al Omairi(Abu AlHassan)21-Apr-11 16:21 
AnswerRe: Closing a window with button?? Pin
enhzflep3-May-11 7:53
enhzflep3-May-11 7:53 
QuestionHow to open Perl files / Perl Module files in Design Layout Pin
sr15920-Apr-11 20:04
sr15920-Apr-11 20:04 
QuestionFuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
edrianhadinatazz18-Apr-11 20:35
edrianhadinatazz18-Apr-11 20:35 
AnswerRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
edrianhadinatazz18-Apr-11 20:38
edrianhadinatazz18-Apr-11 20:38 
GeneralRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
User 171649218-Apr-11 23:07
professionalUser 171649218-Apr-11 23:07 
GeneralRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
Smithers-Jones19-Apr-11 2:53
Smithers-Jones19-Apr-11 2:53 
GeneralRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
edrianhadinatazz28-Apr-11 18:31
edrianhadinatazz28-Apr-11 18:31 
Questioncheckboxes from hell Pin
Joan M13-Apr-11 5:24
professionalJoan M13-Apr-11 5:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.