I am a bit new to PHP and forms. I'm trying to send some variables from one page to another in a PHP form.
This is the form:
<form name="dates" action="document_creation/7bform.php" method="post" onsubmit="return mandatoryFields()">
<table width="748" border="0" cellspacing="2" cellpadding="2">
<tr>
<td class="main_text">
<div align="right" class="main_text">*Contract Start Date:</div>
</td>
<td>
<input name="start_date" type="text" value="YYYY-MM-DD" maxlength="100" class="datepick" id="date1" />
</td>
</tr>
<tr>
<td class="main_text">
<div align="right" class="main_text">*Contract End Date:</div>
</td>
<td>
<input name="end_date" type="text" value="YYYY-MM-DD" maxlength="100" class="datepick" id="date2" />
</td>
</tr>
<tr>
<td height="36" colspan="2">
<table width="100" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="68"> <input name="submit" type="submit" id="Submit" value="Generate 7B Form" <?php if($disable ==1){?>disabled<?php }?>/></td>
<td width="48">
<label><input type="reset" name="reset" value="Reset" /></label>
</td>
<td width="46"><div align="center"><a href="javascript:history.go(-1);">Back</a></div></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
I want to pass start_date
and end_date
to another page document_creation/7bform.php
and it's not working. document_creation/7bform.php looks like this:
<?php
$start_date = ($_POST['start_date']);
$end_date = ($_POST['end_date']);
When I try to print these variables, they come out as blank. Where am I going wrong?
Everything looks fine, so I think your function mandatoryFields()
is returning false.
Other than that, you may want to use this on your retrieving page:
if(isset($_POST['start_date']) && !empty($_POST['start_date'])){
// now assign values
}
if(isset($_POST['end_date']) && !empty($_POST['end_date'])){
// now assign values
}