Hi,
I am struggling with a form in php. I am trying to add a form by using the include function. I want to include thsi form on all pages so it would be very useful if I can save the current page name somewhere so that I can use to validate the form.
For example, this is the form I am trying to include.
<?php
if(!empty($errors))
{
if(isset($errors['sendError']))
{
echo '<p><strong class="error">There was a problem with our system please contact us directly.</strong></p>';
}
else
{
echo '<p><strong class="error">Please check the form below for errors.</strong></p>';
}
}
?>
<form action="index.php" method="post" id="form1">
<p>
<label><?php if(isset($errors['name'])) { echo '<span class="error">'; } ?>Name<font color="red">*</font>: <?php if(isset($errors['name'])) { echo '</span>'; } ?></label>
<input id="search1" id="complete" type="text" value="<?php echo $form['name']; ?>" name="name" size="60" align="right" style="background:#EEF5A4" /><br />
<label><?php if(isset($errors['company'])) { echo '<span class="error">'; } ?>Company: <?php if(isset($errors['company'])) { echo '</span>'; } ?></label>
<input id="search1" id="complete" type="text" value="<?php echo $form['company']; ?>" name="company" size="60" align="right" /><br />
<label><?php if(isset($errors['phone'])) { echo '<span class="error">'; } ?>Phone Number: <?php if(isset($errors['phone'])) { echo '</span>'; } ?></label>
<input id="search1" id="complete" type="text" value="<?php echo $form['phone']; ?>" name="phone" size="60" align="right" /><br />
<label><?php if(isset($errors['email'])) { echo '<span class="error">'; } ?>Email<font color="red">*</font>: <?php if(isset($errors['email'])) { echo '</span>'; } ?></label>
<input id="search1" id="complete" type="text" value="<?php echo $form['email']; ?>" name="email" size="60" align="right" style="background:#EEF5A4" /><br />
<label><?php if(isset($errors['enquiry'])) { echo '<span class="error">'; } ?>Enquiry: <?php if(isset($errors['enquiry'])) { echo '</span>'; } ?></label>
<textarea id="search1" id="complete" textarea name="enquiry" rows=4 cols=40 value="<?php echo $form['enquiry']; ?>" name="enquiry" size="60" align="right"></textarea>
</p>
<p>
<input type="submit" class="formbutton" value="Submit" /> <input type="reset" class="formbutton" value="Reset" />
</p>
<p><font color="red">*</font> Denotes a required field</p>
</form>
Because I am going to use this form on all pages, I would like it to include whatever the filename is rather than index.php in the first line of the form so that when the user clicks submit, it will stay on the same page but validate the form based on the mandatory fields.
I don't know if the question is clear. I would very much appreciate any help at all.
Thank you very much.
Storing filename in php
Moderator: General Moderators
Re: Storing filename in php
Code: Select all
<form action="<?php echo htmlentities($_SERVER["REQUEST_URI"]); ?>" method="post" id="form1">Code: Select all
<form action="<?php echo htmlentities(strtok($_SERVER["REQUEST_URI"], "?")); ?>" method="post" id="form1">