I have a problem in my codes. Obviously, I’m beginning to program in PHP and know nothing about its advanced concepts. So I’m asking of your help. I’d like to add 2 months to the end date the user input. I tried this code below:
protected function inputEndDate() {
$value = $this->endDate;
$html = "";
$html .= '<label for="enddate">End Date:</label>' . PHP_EOL;
$html .= '<input type="text" readonly name="enddate" id="enddate" value="'.$value.'">';
$html .= '<input type="button" id="enddatebutton" onclick="getEndDate()">' . PHP_EOL;
return $html;
}
protected function inputExpiryDate() {
$value = $this->endDate;
$date = date('Y/m/d', strtotime("$value +2 month"));
$html = "";
$html .= '<label for="expirydate">Expiry Date:</label>';
$html .= '<input type="text" readonly name="expirydate" id="expirydate" value="'.$date.'">';
$html .= '<input type="button" id="expirydatebutton" onclick="getExpiryDate()">' . PHP_EOL;
return $html;
}
But when I run the program, it’s not displaying the correct value; however it’s displaying the added two months of its start date. Please help. Thanks.
I am not sure if i understand your question.
If i call the php function inputEndDate() it renders this html for me
The value of the input-field enddate is empty because on my code
$this->endDateis empty.Where do you get or fill
$this->endDate?If all 3 input-fields are on the same page you need javascript to change the value of expireDate based of the input of endDate – see my updated jsfiddle-example.
Update after review of php code
I took a look into your code – i could not find the spot where you are filling the server-side php var
this->endDate. Based on your other question how to use change event to add dates in javascript i am unsure where the problem lies.public function setEditBallpark()and the line$this->endDate = $this->ballparkDetails->getBallparkDetailsEndDate();this->endDateyou have to post the value of the client to the server (normal post or ajax). In line 17 is a comment# $_POST["enddate"]but the only place that may be getting the post value is this line$this->endDate = $this->createBallparkController->getFormEndDate();on line 75. But the method namefunction setErrorForm()lets me assume that this method is not relevant for the normal post case.