Refactoring: Getting rid of an optional variable for a function

chivasregal57

New Member
Here's the situation; below is a piece of PHP code which is frequently reused.\[code\]if (! isset($_REQUEST['process_form']){ // render form echo "<form>"; // snipped // important bit! Remember which id we are processing echo "<input hidden='id' value='http://stackoverflow.com/questions/3870889/$id'>"; // snipped} else { // process the form}\[/code\]I wish to encapsulate this into a function, akin to\[code\] class ProcessForm() { function execute(array $request, $id) { }; }\[/code\]The issue here is; the $id parameter is only needed when rendering the form. When processing the form after a user input or through an AJAX handler, I don't need the $id at all. How could I refactor to get rid of the optional variable $id?
 
Back
Top