<?php function my_plugin_settings_page() {?>
<div class="wrap">
<h2>Staff Details</h2>
<form method="post" action="options.php">
<?php settings_fields( 'my-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-plugin-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Accountant Name</th>
<td><input type="text" name="accountant_name" value="<?php echo esc_attr( get_option('accountant_name') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Accountant Phone Number</th>
<td><input type="text" name="accountant_phone" value="<?php echo esc_attr( get_option('accountant_phone') ); ?>" /></td>
</tr>
</table>
<?php submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings' );
if (isset($_GET['submit'])) {
header('Location: wamp\www\wordpress\wordpress\wp-content\plugins\MaximoPlugin\andra.php');
exit;
}?>
</form>
</div>
My question is, can i redirect a user to another php file in wordpress by adding action to the button_submit ?
So it has like two events. Saving and then redirect the user to another page.
Is this possible on a way. BTW im new to php and wordpress so im sorry for the bad code and stuff.
the if statement isent any good i know, but how can i check if the buttons is submitted and then redirect the user to another wordpress page..(another php site.)
Please give me some input for what i can do or should do.
EDIT:
Ok i changed it to a include, but dont get any response.
</table>
<?php submit_button();
if(isset($_POST['submit']))
{
include('andra.php');
}
}?>
You can use wp_redirect http://codex.wordpress.org/Function_Reference/wp_redirect to redirect the user to another URL. Simply save your data before redirect call.
<?php
wp_redirect( $location, $status );
exit;
?>
The questions is not very clear so I will show two solutions, you can pick the one suits you more:
SOLUTION 1:
Make another file handle_my_request.php
Change the following lines in your code:
<?php submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings' );
if (isset($_GET['submit'])) {
include_once("handle_my_request.php");
exit;
}?>
Now in handle_my_request.php, you can easily write the way you want to handle the request. Eg.
<?php
$var1 = $_GET['myvar1'];
do_something($var1);
?>
SOLUTION 2:
You manually need to make another form and post the fields to the other page you want. For this to happen, you can either GET/POST on server side through PHP (using CURL) or you can GET/POST through javascript on client side.
<?php function my_plugin_settings_page() {?>
<div class="wrap">
<h2>Staff Details</h2>
<form method="post" action="options.php">
<?php settings_fields( 'my-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-plugin-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Accountant Name</th>
<td><input type="text" name="accountant_name" value="<?php echo esc_attr( get_option('accountant_name') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Accountant Phone Number</th>
<td><input type="text" name="accountant_phone" value="<?php echo esc_attr( get_option('accountant_phone') ); ?>" /></td>
</tr>
</table>
</form>
<?php
submit_button( 'Save Settings', 'primary', 'wpdocs-save-settings' );
if (isset($_GET['submit']))
{ ?>
<form name="redirection_form" action="http://anotherwebsite.com" method="post">
<input type="hidden" name="accountant_name" value="<?php echo esc_attr( get_option('accountant_name') ); ?>" />
<input type="hidden" name="accountant_phone" value="<?php echo esc_attr( get_option('accountant_phone') ); ?>" />
</form>
<script type="text/javascript">
document.redirection_form.submit();
</script>
<?php } ?>
</div>
Needless to say here that you need to change the variables and method and action of the form to match the next page you are redirecting to.
As I said before, the same can be achieved by PHP CURL.
<form method="post" action="options.php">
<input type='hidden' name='option_page' value='my-plugin-settings-group' /><input type="hidden" name="action" value="update" /><input type="hidden" id="_wpnonce" name="_wpnonce" value="fc1447e3e7" /><input type="hidden" name="_wp_http_referer" value="/wordpress/wordpress/wp-admin/admin.php?page=my-plugin-settings&settings-updated=true" /> <table class="form-table">
<tr valign="top">
<th scope="row">Accountant Name</th>
<td><input type="text" name="accountant_name" value="1" /></td>
</tr>
<tr valign="top">
<th scope="row">Accountant Phone Number</th>
<td><input type="text" name="accountant_phone" value="1" /></td>
</tr>
</table>
<p class="submit"><input type="submit" name="wpdocs-save-settings" id="wpdocs-save-settings" class="button button-primary" value="Save Settings" /></p>
This is the source view. And yes the andra.php is in same directory.
Im making a plugin for Wordpress, do it have something to do with that ?
Related
I am working on the settings api of the wordpress but can't save the settings, as it returns nothing. I can't understand what am i doing wrong here. I am new to wordpress development so can't figure it out.
<?php
add_action( 'admin_init', function() {
register_setting( 'my-plugin-settings', 'map_option_1' );
});
function my_plugin_page() {
?>
<div class="wrap">
<form action="admin.php?page=creww_dashboard" method="post">
<?php
settings_fields( 'my-plugin-settings' );
do_settings_sections( 'my-plugin-settings' );
?>
<table>
<tr>
<th>Api Key</th>
<td><input type="text" placeholder="Your name" name="map_option_1" value="<?php echo esc_attr( get_option('map_option_1') ); ?>" size="50" /></td>
</tr>
<tr>
<td><?php submit_button(); ?></td>
</tr>
</table>
</form>
</div>
<?php
}
my_plugin_page();
I am looking to display the current value of the NumberedEntered value in the input box.
Currently it will only display the current value when I click submit then refresh. Does anyone know how I can echo it back as soon as I click submit?
Thanks.
<?php foreach($users as $user) : ?>
<tr>
<form action "index.php" method "post" name='form1'>
<td align="center" width="40%" ><?php echo $user['FullName']; ?><input type="hidden" Name="FullName" value="<?php echo $user['FullName']; ?>" /></td>
<td width="30%"><input type="number" name="NumberedEntered" value="<?php echo $user['NumberedEntered']; ?>" /></td>
<td><input type="submit" value="submit"></td>
</form>
</tr>
<?php endforeach; ?>
I am building a custom plugin which i plan to sell, but i am having problem storing my get request values in the plugin URL.
I have this URL:
/wp-admin/admin.php?page=step-one&filename=Styles_For_Less-Styles_For_Less_Product_Catalog.txt
and when the submit button on that page is clicked it should go to page with this URL:
/wp-admin/admin.php?page=step-two&filename=Styles_For_Less-Styles_For_Less_Product_Catalog.txt&header=0&delimiter=%7C"ed=&step2=Step+2+%3E%3E
But i doesn't instead it goes here:
/wp-admin/admin.php?header=1&delimiter=%2C"ed=&step2=Step+2+%3E%3E
<form method="GET" action="<?php echo admin_url( "admin.php?page=step-two&filename=$filename&", "http" ); ?>">
<table border="1" cellpadding="4">
<tr>
<td>Header Row:</td>
<td><?php echo $header; ?> </td>
</tr>
<tr>
<td>Delimiter:</td>
<td><?php echo $delimiter; ?> </td>
</tr>
<tr>
<td>Quoted:</td>
<td><?php echo $quoted; ?> </td>
</tr>
</table>
<p><input type="submit" value="Step 2 >>" name="step2">
<input type="reset" value="Reset" name="B2"></p>
</form>
Any help greatly appreciated.
Instead of appending data in the action url, try creating hidden form inputs.
<form method="GET" action="<?php echo admin_url( 'admin.php'); ?>">
<input type="hidden" name="page" value="step-two" />
<input type="hidden" name="filename" value="<?php echo $filename; ?>" />
<table border="1" cellpadding="4">
// ... rest of the form
I'm generating this table from data passed back from my controller the issue I'm having is that in general the first record returned [ in this case Sephen C. Cox], the "add employee" button does not redirect me but for the rest of the records it works. Does anyone know the problem?
<fieldset id= "results">
<?php if (isset($results ) And count($results)) : ?>
<table id="box-table-a" summary="Employee Sheet">
<thead>
<tr>
<th scope="col">Employee</th>
<th scope="col">Salary</th>
<th scope="col">Bonus</th>
<th scope="col">Supervisor</th>
<th scope="col">Action</th>
</tr>
<?php foreach ($results as $result) : ?>
<tr>
//Primary key <?php echo $result['Employee_ID!'];?>
<td><span class="Employee_name"><?php echo $result['Employee']; ?> </span></td>
<td><span class="Salary"><?php echo $result['Salary']; ?> </span> </td>
<td><span class="Bonus"><?php echo $result['Bonus']; ?> </span> </td>
<td><span class="Supervisor_name"><?php echo $result['Supervisor']; ?> </span></td>
<form action="welcome.php" method="post"> <td><input type="submit" value="Add employee" name="submit[<?php echo $result['Employee_ID'] ?>]" > </td></form>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</thead>
<tbody>
</fieldset>
<form action="welcome.php" method="post">
<td>
<input type="submit" value="Add employee"
name="submit[<?php echo $result['Employee_ID'] ?>]" >
</td></form>
change to
<td>
<form action="welcome.php" method="post">
<input type="submit" value="Add employee"
name="submit[<?php echo $result['Employee_ID'] ?>]" >
</form>
Or even wrap the whole table into one form instead of putting new form into each row. See no any reason in your code why that could be needed
Edit:
Also, take a look at tools like Firebug (FF), Inspector in Chrome and Safary, Developer Tools, or how it is called, in IE. It was completely enough to open you page with one of those tools and notice that browser parsed your code not like you expected.
I have this code which permits me to display all the data in the database as a textarea, I need to update them by clicking a update button!
Based on this one, is supposed to make me edit them, but when i click submit it doesn't...
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center">
<? $id[]=$rows['id']; ?>
<? echo $rows['id']; ?>
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>">
</td>
<td align="center">
<input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>">
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center">
<input type="submit" name="Submit" value="Submit"/>
</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit)
{
for($i=0;$i<$count;$i++)
{
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1)
{
header("location:update_multiple.php");
}
Yes because you forget your id's
<? $id[]=$rows['id']; ?> cannot be passed like that
<input type="hidden" name="id[]" value ="<?php echo $rows['id']; ?>" /><? echo $rows['id']; ?>
and script if($Submit){ should be if($_POST['Submit'] != ''){
You aren't defining $Submit in your post, so the stuff in the { ... } is never executed.
You should try something like this for your update:
if(isset($_POST[$name]))
{
// update stuff
}
In your code, as the if statement never executes, $result is never set, so the user isn't redirected away - it will just show the same page each time.
To check if a post occur when clicking a button should be set as follow:
In the <form>tag add the following
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
And lastly, where you check if the button was clicked:
if(isset($_POST['Submit'])) {
//Update fields
}
Remember that the submit button name field is case sensitive in php