Reputation: 4910
I'm required to edit someone else's code on a website (that person is not reachable) and I don't have much experience on php. At the momment this form redirects to a previous page on submit. I must change it to reload the current page. I've made numerous attempts changing the action field of the form but they all lead to either a blank page or the page it was allready redirecting to. Can someone share a little knowledge here?
<div id="tab-general" class="tab-content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<table>
<tr>
<td><span class="required">*</span> <?php echo $entry_title; ?></td>
<td><input type="text" value="<?php echo $title; ?>" name="title" id="title" /><br />
<?php if ($error_title) { ?>
<span class="error"><?php echo $error_title; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_name; ?></td>
<td><input type="text" value="<?php echo $name; ?>" name="name" id="name" /><br />
<?php if ($error_name) { ?>
<span class="error"><?php echo $error_name; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_email; ?></td>
<td><input type="text" value="<?php echo $email; ?>" name="email" id="email" /><br />
<?php if ($error_email) { ?>
<span class="error"><?php echo $error_email; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_end_date; ?></td>
<td><input type="text" value="<?php echo $end_date; ?>" name="end_date" id="end_date" /><br />
<?php if ($error_end_date) { ?>
<span class="error"><?php echo $error_end_date; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_type; ?></td>
<td><select name="type" id="type" class="type_list">
<?php if ($type) { ?>
<option value="1" selected="selected"><?php echo $text_private; ?></option>
<option value="0"><?php echo $text_public; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_private; ?></option>
<option value="0" selected="selected"><?php echo $text_public; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td><?php echo $entry_status; ?></td>
<td><select name="status">
<?php if ($status) { ?>
<option value="1" selected="selected"><?php echo $text_enabled; ?></option>
<option value="0"><?php echo $text_disabled; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_enabled; ?></option>
<option value="0" selected="selected"><?php echo $text_disabled; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td><br /><h2><?php echo $text_invitees; ?></h2></td>
<td></td>
</tr>
</table>
<table id="attendee" class="list">
<thead>
<tr>
<td class="left"><?php echo $entry_att_name; ?></td>
<td class="right"><?php echo $entry_att_email; ?></td>
<td></td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="2"></td>
<td class="left"><a onclick="addAttendee();" class="button"><?php echo $button_add; ?></a></td>
</tr>
</tfoot>
<?php $attendee_row = 0; ?>
<?php if ($attendees) { ?>
<?php foreach ($attendees as $attendee) { ?>
<tbody id="attendee-row<?php echo $attendee_row; ?>">
<tr>
<td class="left"><input type="text" name="attendee[<?php echo $attendee_row; ?>][name]" value="<?php echo $attendee['name']; ?>" size="18" />
<?php if (isset($error_name_attendee[$attendee_row])) { ?>
<span class="error"><?php echo $error_name_attendee[$attendee_row]; ?></span>
<?php } ?>
</td>
<td class="right"><input type="text" name="attendee[<?php echo $attendee_row; ?>][email]" value="<?php echo $attendee['email']; ?>" size="18" />
<?php if (isset($error_email_attendee[$attendee_row])) { ?>
<span class="error"><?php echo $error_email_attendee[$attendee_row]; ?></span>
<?php } ?>
</td>
<td class="left"><a onclick="$('#attendee-row<?php echo $attendee_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a>
</td>
</tr>
</tbody>
<?php $attendee_row++; ?>
<?php } ?>
<?php } ?>
</table>
<div class="buttons"><div class="left">
<a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a></div><div class="right"><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a>
</div></div>
</div>
After checking the content of the $action variable it turns out that it holds the link of the current page. It SHOULD reload the page but it doesn't.
example: this is the link
localhost/index.php?route=account/projects/editProject&project_id=1&akey=98c27892d1e2a13c0dfb9086539f8275
and it is stored in the $action variable. Instead the direction is to the link
localhost/index.php?route=account/projects
Upvotes: 0
Views: 343
Reputation: 13552
If you want the form to submit to the current page, simply, remove action
attribute from your form tag. However, you have to perform a check for a data submision is occured or not to prevent rendering the form or reapeated submitting of the form some thing like the following:
<?php if (isset($_POST['title']) && $_POST['title'] != ''): ?>
//Perform form data processing
<?php else: ?>
// Your form code
<?php endif; ?>
Upvotes: 0
Reputation: 113
Make Sure your action has path equal to your page path then it will submit your form values and will stay on same page
if this page has path like e.g /home/index.php
then
<form action="/home/index.php" method="post" enctype="multipart/form-data" id="form">
and if you have get path from your $action
variable then try echo $action;
to make sure that you have same path of your current page
Upvotes: 2
Reputation: 2191
The $action variable here om the second row should result in the page that you want to reload.
Upvotes: 0