2015年04月

Automatically provide response to HTML form server-side using PHP

I am building an app that extracts data from a website and displays them in my app. I am using PHPQuery to extract data in my server-side code.



However, one page contains an .asp form with two dropdown menus. I need to select an option in both of them and then parse the resulting html. I need to do this server-side, so javascript doesn't seem to be the option.



How can I do so? Can it be done using PHPQuery or some other technology is required?



The page in question is: http://www.bput.ac.in/exam_schedule_ALL.asp



Answers

Since you're using PHP and phpQuery, I suggest you also try cURL.



Explore what the form submits via JavaScript and replicate that via cURL. Do this to get the format of the posted (assumption) data, which you can then replicate in a cURL request to the same endpoints. JavaScript won't be necessary, and you can get the same results you need. In this case, you won't need the item mentioned next.



Alternatively, if you have a browser, such as webkit, phantomJS, etc, you can write an automation script to run those steps and return the results, depending on exactly what you need returned. See more complete examples here: http://stackoverflow.com/a/17449757/573688 for how others suggest you do this. NOTE this is not usually necessary if you just need to emulate POST requests.



This is a non-coded answer because it's not entirely clear what direction helps you the most.



Answers

On page works JavaScript, which should make an AJAX request to the server and pass the selected value from both SELECT.
The server receives the AJAX request, performs the request to the correct address (you can use phpQuery) and prints the response (gets to the response on AJAX request).
JavaScript on the page receives a response to an AJAX request and performs actions affected.



Question

my wife was put on bedrest at 25 weeks. now that here fmla is up they have terminated her because she just had the babies 2 weeks ago. is this legal? her doctor said she should not go back to work for 12 weeks post partum



Answer

First, not all employees are protected under FMLA. If they are protected under FMLA that protection is only for 12 weeks maximum during a qualified year. An employer is generally not required to hold a job open indefinitely for an out of work employee, but some people do qualify for additional protection. You should find an employment law attorney in your area and set an appointment to speak with them. Most consultations of this nature are free.







Question

Hearign For p242/243el


My wife called the cops on me but didn't press charges. There was not blood not even scraches, she just sad i pushed her. I didn't go to jail. Still, we both got a letter from the city attorney for a hearing .


Question: What will happend if my wife doesn't show up? Will the the case be dismissed or not?



Answer

Re: Hearign For p242/243el


It is highly unlikely to be dismissed, it is prosecutors' general policy to vigorously prosecute domestic violence. However, if you weren't arrested at the time, the prosecutor may informally resolve this one. Feel free to contact me if you're serious about getting the legal help you'll need.





Question

california divorce


we are in the process of divorce,the house that was bought before marriage is now worth 300k more.my name was never added to the deed.how much of the 300k of appreciation am i entitled to.



Answer

Re: california divorce


This is a complex question. A review of the facts and agreement when the house was purchased, source of the money used to purchase the house. A discussion of the facts with an attorney will not doubt raise additional issues.



Answer

Re: california divorce


The answer to your question is too complex to be handled over the internet. Many questions must be


ask and answered before any advice can be given to you. You need to sit down with a family law


attorney and go over the entire family situation and assets and he can give you some general ideas about


what will happen. You may be entitled to a great deal. You may be entitled to very little. Good Luck, Pat McCrary






Optional unexpectedly found nil and crash log info

I had this issue happening to me yesterday. I was dealing with a piece of production code that was crashing at a certain point with this crash info



0   Goga  0x00000001000b90b8 function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed> of Goga.NewViewController.emailButtonPressed (Goga.NewViewController)(ObjectiveC.UIButton) -> () (NewViewController.swift:0)
1 Goga 0x00000001000c0488 Goga.NewViewController.(emailButtonPressed (Goga.NewViewController) -> (ObjectiveC.UIButton) -> ()).(closure #2) (NewViewController.swift:872)
2 Goga 0x00000001000bd250 partial apply forwarder for reabstraction thunk helper from @callee_owned (@in ObjectiveC.UIAlertAction!) -> (@out ()) to @callee_owned (@owned ObjectiveC.UIAlertAction!) -> (@unowned ()) (NewViewController.swift:0)


However, when I found the bug, after hours of trying to replicate the issue, any error message for it couldn't be found in the crash log. The bug was showing in XCode instead as:




unexpectedly found nil while unwrapping an Optional value




My question is, how to catch the nil-optional error in production code?



Edit:



Just to add a bit more of a perspective to the original problem, I found the issue in this sample code:



let cell = tableView.cellForRowAtIndexPath(indexPath)  
cell.textLabel.text = "Hello" // CRASH if the cell is not visible in the view


I should have done this instead:



if let cell = tableView.cellForRowAtIndexPath(indexPath) {
cell.textLabel.text = "Hello" // Never get executed if cell is nil
}


Answers

The way to "catch" the "nil-optional error" is simply by writing your code correctly. Don't abuse forced unwrapping and forced down casting.



In this specific case, simply reading the crash details can give us some information:



1   Goga  0x00000001000c0488 Goga.NewViewController.(emailButtonPressed (Goga.NewViewController) -> (ObjectiveC.UIButton) -> ()).(closure #2) (NewViewController.swift:872)


Somewhere around line 872 of NewViewController.swift, you're force unwrapping something that's actually nil (and therefore cannot be unwrapped).



The solution is to go to line 872 of NewViewController.swift, find any occurrences of the exclamation point, determine whether it's a force-unwrapping operator or if it's a boolean operator... and if it's a force unwrapping operator, fix it using Swift's optional binding design patterns.



It could be that you're doing something like this:



let foo = bar!


Or perhaps somewhere bar is declared like this:



var bar: AnyObject!


Then it's never initialized (or at some point set to nil) and then because it's implicitly unwrapped, you're doing something like this:



let foo: AnyObject = bar


These can both lead to the error you're looking at.



Yes, implicitly unwrapped optionals and forced unwrapping can make things slightly more convenient when writing your code, but in the end, all it means is you run into these problems that you have to eventually track down later. And there's no need to do so when Swift has plenty of tools to ensure we're being safe with nil.



Answers

When dealing with optionals you should be conditionally unwrapping them with an if statement.



var yourOptional: String?

if let unwrapped = yourOptional {
// Do something with the variable
} else {
// It was nil
}


Answers

Or use guard it's easier just as you get complex code



guard let optional = someOptional else {
return // or do what need's to be done if nil
}


Answers

Checking API Availability



if #available(iOS 9, OSX 10.10, *) {
// Use iOS 9 APIs on iOS, and use OS X v10.10 APIs on OS X
} else {
// Fall back to earlier iOS and OS X APIs
}


It will come be prepared.





↑このページのトップヘ