PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Weasel5-12
Forum Commoner
Posts: 37 Joined: Tue Sep 16, 2008 6:58 am
Post
by Weasel5-12 » Mon Nov 17, 2008 11:30 pm
Hi, Im developing an online auction site for an assignment as part of my final year project for uni.
And i was wondering if it were possible to instead of, when using forms, sending the data taken from the user ie. a checkbox, and send it to a function vs. sending to a new page(script)??
Here's what i've got so far.
Code: Select all
[color=#0000FF]function[/color] addAdmin($info[[color=#FF0000]'UserID'[/color]]){
$userID = $info[[color=#FF0000]'UserID'[/color]];
$query = [color=#FF0000]"UPDATE users SET Type = 'Admin' WHERE UserID =2 LIMIT 1"[/color];
$result = [color=#0000FF]mysql_query[/color]($query)[color=#0000FF] or die[/color] ([color=#FF0000]"Couldn't execute query"[/color]);
}
...
...
...
$query = [color=#FF0000]"SELECT * FROM users ORDER BY Username ASC"[/color];
$result = [color=#0000FF]mysql_query[/color]($query);
[color=#0000FF]echo[/color] [color=#FF0000]"<form action='"[/color].addAdmin().[color=#FF0000]"' method='post'>"[/color];
[color=#008000]while[/color]($info = [color=#0000FF]mysql_fetch_array[/color]( $result )){
[color=#FFBF00]// Output Check List[/color]
[color=#008000]if[/color]($info['Type'] != [color=#FF0000]"Admin"[/color]){
[color=#0000FF]echo[/color] [color=#FF0000]"<input type='checkbox' name='Username[]' value='"[/color].$info['Username'].[color=#FF0000]"'> "[/color].$info['Username'].[color=#FF0000]"<br>"[/color];
[color=#0000FF]echo[/color] [color=#FF0000]"<input type='hidden' name='hidden' value='"[/color].$info['UserID'].[color=#FF0000]"'"[/color];
}
}
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Nov 17, 2008 11:42 pm
It's called "AJAX".
Google for it, you'll find a lot.
Syntac
Forum Contributor
Posts: 327 Joined: Sun Sep 14, 2008 7:59 pm
Post
by Syntac » Tue Nov 18, 2008 2:50 pm
Oh, and did you know the syntax highlighting is automatic? Just use [syntax=php].[/syntax]
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Tue Nov 18, 2008 3:00 pm
You don't actually have to use action in a form. Simply post the form to itself and validate from the top of the script.
i.e.
Code: Select all
//validate form post
if(isset($_POST['submit']))
{
//do something
}
echo'<form name="form1" method="post">';
echo'<label>Name</label><input type="text" name="strName" /><br />';
echo'<input type="submit" name="submit" value="Submit" />';
echo'</form>';
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Nov 18, 2008 4:57 pm
aceconcepts wrote: You don't actually have to use action in a form. Simply post the form to itself and validate from the top of the script.
Au contraire, the action is the one
required attribute of a form. Method, name, id...
those are all optional.
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Tue Nov 18, 2008 5:45 pm
If you omit action from the form's paramaters it defaults to itself - give it a go
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Nov 18, 2008 5:55 pm
aceconcepts wrote: If you omit action from the form's paramaters it defaults to itself - give it a go
Code: Select all
<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->
<!ATTLIST FORM
%attrs; -- %coreattrs, %i18n, %events --
action %URI; #REQUIRED -- server-side form handler --
method (GET|POST) GET -- HTTP method used to submit the form--
enctype %ContentType; "application/x-www-form-urlencoded"
accept %ContentTypes; #IMPLIED -- list of MIME types for file upload --
name CDATA #IMPLIED -- name of form for scripting --
onsubmit %Script; #IMPLIED -- the form was submitted --
onreset %Script; #IMPLIED -- the form was reset --
accept-charset %Charsets; #IMPLIED -- list of supported charsets --
>
http://www.w3.org/TR/1999/REC-html401-1 ... tml#h-17.3
It defaults because that's what your browser's developers decided to do.
My car can do 90mph but that doesn't mean I should.
Syntac
Forum Contributor
Posts: 327 Joined: Sun Sep 14, 2008 7:59 pm
Post
by Syntac » Tue Nov 18, 2008 6:00 pm
Include it, because you should.
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Tue Nov 18, 2008 6:01 pm
Honestly, try it. It works just fine.
Although it's good to know that technically it's a required attribute
Weasel5-12
Forum Commoner
Posts: 37 Joined: Tue Sep 16, 2008 6:58 am
Post
by Weasel5-12 » Wed Dec 03, 2008 1:25 am
I found a seperate script to use instead.
Code: Select all
..
$locaction = $_SERVER['PHP_SELF'];
echo "<form method='post' action='".$locaction."'>";
..