I've searched but can't find an answer.
There is a website with a contact form, the address end's like this: /?page_id=42, what I want is to send an email from this contact form through the iPhone, without entering the site, through PHP.
From the iPhone textfields.
so I did like this:
/?page_id=42contactname=hello&contactsubject=hey&contactemail=yositsa#gmail.com&contactmessage=this is just checking message
but I dont know why, it isn't sending me the message, what have I done wrong from the PHP and Objective-C side..
I dont have much knowledge in PHP and I'm new to Objective-C.
Thanks! :)
Like some other people have mentioned - does your PHP contact page use GET request variables? If unsure, check your contact page and look for $_POST. If you see this, just as a quick fix change all of your $_POST references to $_REQUESTS (which allow both POST and GET variables).
If this works, and you'd still like to use POST - then use something like ASIHTTPRequest in your iOS app to post the variables over.
URL you mentioned is like
`/?page_id=42contactname=hello&contactsubject=hey&contactemail=yositsa#gmail.com&contactmessage=this is just checking message`
I suspect here that you are missing & (ampersand) sign between page_id=42 and contactname. I am not sure this is the mistake but currently this is what I see from your current URL.
If this is not the problem try printing variables in which you fetch those parameters as all people have mentioned.
Or post your PHP and iOS side code so we can have a look in to that what is the exact problem.
Hope this helps.
The contact form probably works with POST variables. It's not a PHP thing, but an HTML thing. You need to send the variables in the body of an HTTP request, and you also need that request to be of type POST.
The query string you are trying to use means it's GET request, does your PHP form accept variables from the GET requests ?
Also make sure there are no hidden fields in the form that you might not be including.
I know it may be a bit late, but I just created a drop-in view controller to create an iOS "form" and post the variables to a web server. Not sure if the OP had access to the server side, but you can adapt this code to POST variables to existing web forms too.
It's on Github here:
https://github.com/mikecheckDev/MDContactForm
Let me know if you have any questions about it or need help and/or more features. It is still early in development but I found it useful in my project!
Related
I'm working on a simple contact form right now that will just post to a /contact endpoint and update a message via ajax if success or failure. I plan on having other forms such as account settings work in this sort of way too so I can avoid having to refresh the page. I'm new to working with ajax and creating my own api's so any help would be awesome.
Basically what I want to do right now is verify that the post request/body is being sent from my website and not an external source. I thought about just checking the url with PHP but I'm not sure if this can be spoofed. Any help would be great, thanks!
One method is to create a unique ID/GUID when the form is created, embed it in the form (hidden field, JS var), and also store it to $_SESSION. When your script is called via AJAX, pass this value in the AJAX call, and then compare it on the server side. That way, you not only know it came from your page, but from the same session.
To check this things security i would pass a hash generated on the client (with certain rules) and check if the hash is valid on the server php endpoint. You can use $_SERVER["HTTP_REFERER"] to check if the domain matches but that can be easily spoofed and sometimes it may actually not even be available. I hope i answered the question. This is what i understood you were asking.
My question maybe unheard of or may even be impractical.
But, I believe it is practical and acceptable.
Problem: PHP request and response in background thread.
Problem constraints:
You know it uses POST method.
It has two fields fname and lname as html ids that need to be filled.
You get response in the same page i.e. index.php .
Pseudocode to solve the problem:
Open the website in background. Something like openURL("xyz(dot)com");
Read the data sent in html format.
Change the value of the fields fname and lname to required fields "Allen" and "Walker."
Now, submit the fields back to the server. ( Page has a submit button.)
Note: PHP code has a standard if-else check to check for those values. If the field is properly set, it then says "Success" else "Failed"
Again, get the response sent by the server.
Check if "Success" was returned.
If "success" was returned, UPDATE UI thread for saying "JOB done".
Else, "Job failed."
Note: I am not talking about using a WebView. Everything happens via a service or AsyncTask.
Now, this is a simple question, and any ideas or a direction is acceptable.
So, to recap. You have to open a webpage in background, change its field, submit it back and then get the response.
I know we can open a website and get its content. But, I would also like to know if what I said is possible or not. And, I know it is possible. And, that I only lack the knowledge on Java Web API, could you please guide me on this.
Thank You. And, Have a Good day!
use this link for best solution of calling web service without using WebView.
In this example fname and lname sent in namevaluepairs we get responce in json formet and parse json and get data also json parse defined in examples.
What you are trying to achieve is to create a webservice call using a AsyncTask.
Like you have mentioned, you can make a post request within the AsyncTask, passing in the variables required for the request.
You can find a good example as shown: Sending HTTP Post Request with Android
What is PHP action? Is there anything called as PHP action? I tried to google it and look up different web forums but was not able to find anything related to this. A recruiter had sent me an email where he wanted someone with skills/experience in "PHP action". Just curious.
If it stood on its own like that, my guess is the recruiter doesn't know what he's talking about. Maybe it was a copy+pasting error from "Actionscript" or something.
"PHP Action" is not a defined term. At least not one I have ever heard of.
My tendency would be to respond anyway, and then sort the details out later when getting interviewed by the actual employer.
Action is a term used throughout the Symfony Framework 1.x, perhaps he was referring to that. They are basically page controllers. Few examples:
// apps/myApp/modules/myModule/actions/actions.class.php
public function executeIndex() {}
public function executeResult() {}
he Action attribute is crucial. It means, "Where do you want the form sent?". If you miss it out, your form won't get sent anywhere. You can send the form data to another PHP script, the same PHP script, an email address, a CGI script, or any other form of script.
In PHP, a popular technique is to send the script to the same page that the form is on – send it to itself, in other words. We'll use that technique first, but you'll see both techniques in action.
So we're going to be sending the form data to exactly the same page as the one we have loaded – to itself. We'll put some PHP on the page to handle the form data. But for now, save your work again and then click your submit button. You won't see anything different, but you shouldn't see any error message either!
Once your script has an Action attribute set, you can then Submit it. Which we'll see in the next part.
What I'm trying to do is:
I have a form. I submit that form. In the code of the target script I want to make some validations. In a certain case, I want to make a POST to another URL. I don't want to just make a redirect to an URL.
I don't know if this is possible, that's why I'm asking.
I'm working with PHP.
Thanks!
To the people who suggested cURL: Building a request like so will send the data on behalf of the server not the client. I don't think he wants that.
He wants POST forwarding and that, if it were to exist (and I don't think it does), should be implemented by the browser.
What I suggest is to use an AJAX call to make the validation before posting. And then depending on the response you choose the destination for posting (on the client side).
To summarize: You request a validation from the client. You do that validation on the server. You send back instructions to the client. You post according to the instructions received from the server.
I'm not sure if you understand this, but any details of requests made by the user(client) are known in full by him. You can't make him POST to an URL, have a password in that POST, and not have access to that password.
Note: If it's easier you can read JavaScript and PHP instead of client and server.
It is definitely possible. You could use the PHP cURL library to easily create a POST request. But this might be overkill for what you are trying to achieve. Is it a possibiity to do the validation in JavaScript and change the form action attribute with JavaScript after submitting?
In what case would you need to post it to another PHP file.
Couldn't you simply use IF statements to redirect the script to another script depending on the results of the validation?
I haven't officially started learning PHP, just skimming through a couple tutorials and I have a question. Why would some one choose to use Get vs Post? Why would you ever want the data shown in the url bar? I understand post is used for passwords and important info but I don't understand why you would use get instead of just post all the time?
Thanks for any insight.
$_GET is useful for pages where users are requesting data - such as a search page, and pages that a user might want to bookmark and share with others. Actions that should be readonly.
$_POST is useful for pages where users are "posting" data - such as a signup form. $_POST should be used when you don't want your visitors to be able to bookmark page. Actions that write data.
As prodigitalson added: you may use $_POST or $_GET for any operation, but it is good practice to use them as described above.
If you want people to be able to share the link with their friends...for eg http://example.com/products.php?product_id=12
GET requests are idempotent. POST requests change server state.
This is an HTTP question, not a PHP question.
are you planning to fill your website with forms and buttons on each link?? every link you see in this site is sending GET variables.. maybe your question is related to the "method" attribute in a form, if that's the case, well 90% of the cases post is a better choice
dont worry about the security :) just because you dont see the information in the navigation bar doesnt mean that its secured, watching the information sent by post is only two clicks away ;)
Some times you have to pass params(data) to a script without form submit OR want to share that script to someone. In that case $_GET is useful.
GET method may result in long URLs, and may even exceed some browser and server limits on URL length.
GET can be used for multiply reasons..
If you want to share a URL with your friend, like http://site.com/share.php?id=123 <- Often used.
Its often used to do dynamic actions.
POST is often used when sensetive information should not be shared.
You can look it up on google to learn more =)