PHP is server-side, so it takes server requests and creates responses. This means that PHP will not see the data in your form until after the submission. This does not allow time for the action attribute to be modified. You could technically accept the form input to a default action, and then recreate the same request and process it on another URL, but that's fairly complicated.
I think you should be looking into a JavaScript solution. You're interested in the <form> element and the value of the <input> element. You'll want to set the "action" attribute of the <form> element to the value of the <input> element when the <form> element's "onSubmit" event occurs.