Check for input and post to PHP - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Check for input and post to PHP (/showthread.php?tid=84245)
Check for input and post to PHP by r3m!xXx on 06-10-2008 at 02:07 PM
first of all: hey! im teh new one!!11
i got a lil script knowledge issue:
imagine a window with 3 editable text inputs. text1, text2 and text3.
at the bottom i got a submit button.
what i dont know:
i need to check all of the 3 texts boxes for emptyness! if text1 empty -> error msg, else if text2 is empty msg -> error else if text 3 is empty -> error msg
if all of them are fillled with text, they should be put in a variable seperately. e.g. t1, t2 and t3, because i want to put them into a post script later for a mysql_query.
i guess this one would work with my idea: http://shoutbox.menthix.net/showthread.php?tid=82911
would be fine if someone could assist me.
EDIT: they dont need to be seperately at all
RE: Check for input and post to PHP by matty on 06-10-2008 at 02:10 PM
Did you check the Scripting Documentation?
In there you will find that when they press the button you can use
code: if ( pPlusWnd.GetControlText("Text1") === "" ) {
// error
}
RE: Check for input and post to PHP by r3m!xXx on 06-10-2008 at 02:17 PM
should have pointed it out clearlier, my problem is the error stuff. how do i prevent the script from writing unfilled stuff in my database?
RE: Check for input and post to PHP by Volv on 06-10-2008 at 02:21 PM
quote: Originally posted by r3m!xXx
should have pointed it out clearlier, my problem is the error stuff. how do i prevent the script from writing unfilled stuff in my database?
That is what matty's code does, it checks if the textbox is empty.
You could also/alternatively add a check in your PHP code:
code: if ($_POST['t1'] == "") {
// error
} else {
// continue
}
RE: RE: Check for input and post to PHP by r3m!xXx on 06-10-2008 at 02:26 PM
quote: Originally posted by Volv
That is what matty's code does, it checks if the textbox is empty.
You could also/alternatively add a check in your PHP code:
code: if ($_POST['t1'] == "") {
// error
} else {
// continue
}
thats a good solution, i didnt even think that way around.
RE: Check for input and post to PHP by Matti on 06-10-2008 at 02:26 PM
Yes, that thread will help you out with most of your problems about sending the information. Checking for emptiness isn't that hard either.
Here's some kind of scheme which you should base your code on.
- Make a function for your window's CtrlClicked event:
code: function OnWindowIdEvent_CtrlClicked(PlusWnd, CtrlId) {
...
}
- In that function, check if the CtrlId matches the ID of your submit button.
- If it matches, we'll firstly have to get the three text inputs:
code: var t1 = PlusWnd.GetControlText("text1");
var t2 = PlusWnd.GetControlText("text2");
var t3 = PlusWnd.GetControlText("text3");
- Then, we'll check the emptiness:
code: if(t1 == "" || t2 == "" || t3 == "") {
//Show an error message.
//For more information, check the MSDN page of MessageBox.
//http://msdn.microsoft.com/en-us/library/ms645505.aspx
Interop.Call("user32", "MessageBoxW", 0, "A required field has been left empty.\nPlease check your inputs and try again.", "Field left empty", /* MB_ICONEXCLAMATION */ 0x30);
} else {
//Input is valid, send the information to the PHP page!
...
}
- If it's not empty, the information can be sent to the PHP page by using the method explained in [Tutorial] Communicating with web pages. Depending of how your PHP page wants to receive the information, you can either send it using GET or POST. The tutorial explains it very well, I'm sure you'll find out what you have to do.
Yes, the error stuff can be done with a call to MessageBox.
(The W after the function's name indicates that the Unicode version should be used, it's not a typo!)
quote: Originally posted by Volv
You could also/alternatively add a check in your PHP code:
code: if ($_POST['t1'] == "") {
// error
} else {
// continue
}
You should have that code in your PHP anyway to prevent malicious attacks, but a check in the script itself is more useful because you can get a nice error box before any data is transmitted. I recommend using both for the best experience for both you and the users!
RE: Check for input and post to PHP by r3m!xXx on 06-10-2008 at 02:45 PM
thx for ur huge help, but i didnt get point 2 and 3.
what does #2 actually make? could you give me a hint where i can find that in this documentation?
do i have to put #3 and #4 in the function u told me to make in #1?
RE: Check for input and post to PHP by Felu on 06-10-2008 at 02:49 PM
code: function OnWindowIdEvent_CtrlClicked(PlusWnd, CtrlId) {
if(CtrlId == "BtnSubmit") { // Thats Point #2 to check whether its the submit button clicked. Replace BtnSubmit with whatever ID you've given to the submit button
var t1 = PlusWnd.GetControlText("text1"); //Point #3
var t2 = PlusWnd.GetControlText("text2");
var t3 = PlusWnd.GetControlText("text3");
//here goes the rest of the code....
} // <3 Volv
}
RE: Check for input and post to PHP by r3m!xXx on 06-10-2008 at 02:54 PM
aight, thats another huge help, thanks to you guys.
RE: RE: Check for input and post to PHP by Volv on 06-10-2008 at 03:03 PM
quote: Originally posted by Felu
code: function OnWindowIdEvent_CtrlClicked(PlusWnd, CtrlId) {
if(CtrlId == "BtnSubmit") { // Thats Point #2 to check whether its the submit button clicked. Replace BtnSubmit with whatever ID you've given to the submit button
var t1 = PlusWnd.GetControlText("text1"); //Point #3
var t2 = PlusWnd.GetControlText("text2");
var t3 = PlusWnd.GetControlText("text3");
//here goes the rest of the code....
}
You forgot to close your if()
RE: Check for input and post to PHP by Felu on 06-10-2008 at 03:06 PM
quote: Originally posted by Volv
You forgot to close your if()
Oops.. edited.
RE: Check for input and post to PHP by r3m!xXx on 06-10-2008 at 03:37 PM
hey guys, its me again!
code: var url = "http://www.example.com";
var data = "var1=some%20data&var2=some%20more%20data";
Interop.Call("wininet.dll", "DeleteUrlCacheEntryW", url);
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", data.length);
xmlhttp.setRequestHeader("Connection", "close");
[...]
how do i handle the vars here? is my stuff already saved in $var1, $var2 and $var3? i guess not because php doesnt know that variable... seems like ill have to use the GET array method allthough i took the post method. or is it saved in $_POST[t1] and so on?
excuse me for not understanding...
|