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

Linux, Apache, MySQL, PHP

 
AnswerRe: E-mail tracking in PHP Pin
cjoki25-May-11 5:32
cjoki25-May-11 5:32 
QuestionHow to Compile a .PHP File Pin
Sajju201114-May-11 9:06
Sajju201114-May-11 9:06 
AnswerRe: How to Compile a .PHP File Pin
Luc Pattyn14-May-11 11:09
sitebuilderLuc Pattyn14-May-11 11:09 
QuestionBLDMAKE ERROR: Can't find any RVCT installation. Pin
Raj Aryan 100110-May-11 5:03
Raj Aryan 100110-May-11 5:03 
AnswerRe: BLDMAKE ERROR: Can't find any RVCT installation. Pin
Uilleam23-Jul-11 15:17
Uilleam23-Jul-11 15:17 
QuestionExecuting PHP script without leaving the page Pin
AmbiguousName3-May-11 5:03
AmbiguousName3-May-11 5:03 
AnswerRe: Executing PHP script without leaving the page Pin
enhzflep3-May-11 5:09
enhzflep3-May-11 5:09 
AnswerRe: Executing PHP script without leaving the page PinPopular
enhzflep3-May-11 6:39
enhzflep3-May-11 6: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 0:10
astra.20123-May-11 0:10 
QuestionPHP Form help Pin
Dave McCool30-Apr-11 8:54
Dave McCool30-Apr-11 8:54 
AnswerRe: PHP Form help Pin
Peter_in_27801-May-11 4:59
professionalPeter_in_27801-May-11 4:59 
GeneralRe: PHP Form help Pin
Dave McCool1-May-11 5:08
Dave McCool1-May-11 5:08 
Questionthe apache service doesn't start Pin
Farhaneh25-Apr-11 20:10
Farhaneh25-Apr-11 20:10 
AnswerRe: the apache service doesn't start Pin
Gerben Jongerius25-Apr-11 20:41
Gerben Jongerius25-Apr-11 20:41 
QuestionAn XML printer thingy Pin
freeluna22-Apr-11 14:23
professionalfreeluna22-Apr-11 14:23 
QuestionClosing a window with button?? Pin
AmbiguousName21-Apr-11 6:00
AmbiguousName21-Apr-11 6:00 
AnswerRe: Closing a window with button?? Pin
Ali Al Omairi(Abu AlHassan)21-Apr-11 15:21
professionalAli Al Omairi(Abu AlHassan)21-Apr-11 15:21 
AnswerRe: Closing a window with button?? Pin
enhzflep3-May-11 6:53
enhzflep3-May-11 6:53 
QuestionHow to open Perl files / Perl Module files in Design Layout Pin
sr15920-Apr-11 19:04
sr15920-Apr-11 19:04 
QuestionFuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
edrianhadinatazz18-Apr-11 19:35
edrianhadinatazz18-Apr-11 19:35 
AnswerRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
edrianhadinatazz18-Apr-11 19:38
edrianhadinatazz18-Apr-11 19:38 
GeneralRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
User 171649218-Apr-11 22:07
professionalUser 171649218-Apr-11 22:07 
GeneralRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
Smithers-Jones19-Apr-11 1:53
Smithers-Jones19-Apr-11 1:53 
GeneralRe: Fuzzy C Means in PHP Code and My SQL Database, Please Help! Pin
edrianhadinatazz28-Apr-11 17:31
edrianhadinatazz28-Apr-11 17:31 
Questioncheckboxes from hell Pin
Joan M13-Apr-11 4:24
professionalJoan M13-Apr-11 4: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.