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
Related
I'm trying to send multiples values to a PHP form.
This is the form that I use to send values:
<form id="form1" name="form1" method="POST" action="../WSweb/Factura.php">
<table width="561" height="79" border="1">
<tr>
<td width="30%" height="32">ProductID</td>
<td width="30%" height="32">SKU</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_test1['ProductID']; ?>
<input
type="hidden"
name="Product[id][ProductID]"
value="<?php echo $row_test1['ProductID']; ?>"
/>
</td>
<td><?php echo $row_test1['SKU']; ?>
<input
type="hidden"
name="Product[id][SKU]"
value="<?php echo $row_test1['SKU']; ?>"
/>
</td>
</tr>
<?php } while ($row_test1 = mysqli_fetch_assoc($test1)); ?>
</table>
<input type="submit" value="Update" name="Facturar">
</form>
And this is the action file:
if(isset($_POST['Update']))
{
$ProductID=$_POST['Product'];
print_r(json_encode($ProductID));
}
The problem that I have is when I send multiple values, for example the below table:
ProductID SKU
103 WH004BI
137 VO007BI
I alway get this result:
{"id":{"ProductID":"137","SKU":"VO007BI"}}
When I actually want to get a result like this:
{"id":[{"ProductID":"103","SKU":"WH004BI"},{"ProductID":"137","SKU":"VO007BI"}]}
You're going to want to do something like this:
<form id="form1" name="form1" method="POST" action="../WSweb/Factura.php">
<table width="561" height="79" border="1">
<tr>
<td width="30%" height="32">ProductID</td>
<td width="30%" height="32">SKU</td>
</tr>
<?php $i = 0; ?>
<?php while ($row_test1 = mysqli_fetch_assoc($test1) { ?>
<tr>
<td>
<?php echo $row_test1['ProductID']; ?>
<input
type="hidden"
name="Product[id][<?= $i; ?>][ProductID]"
value="<?php echo $row_test1['ProductID']; ?>"
/>
</td>
<td>
<?php echo $row_test1['SKU']; ?>
<input
type="hidden"
name="Product[id][<?= $i; ?>][SKU]"
value="<?php echo $row_test1['SKU']; ?>"
/>
</td>
</tr>
<?php $i++; ?>
<?php } ?>
</table>
<input type="submit" value="Update" name="Facturar">
</form>
Note that I have put a $i = 0 at the start of the loop, and $i++ at the end of the loop.
Additionally, I have changed the names to the following:
name="Product[id][<?= $i; ?>][SKU]"
Which will prevent the issue you were having in the comment section regarding an ill-formed array.
i update php form and change the value but it cant change it saves the same previous value
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id="total_fees">
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
</tr>
Please see the screenshot of source code and input filed . i changed the value in input field but it remain same in source code and save source code value db
The input values not immediately affect on your input but You will get your new value while you submitting your form.
So submit your form and then print the values of the Request. You will find the new value of total_fees into the request parameters.
HTML CODE
<form name="jqueryForm" method="post" id="jqueryForm" enctype="multipart/form-data" onSubmit="return validme();">
<table border="0" cellspacing="15" cellpadding="0" width="100%" >
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id=total_fees>
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
<td width="40%"></td>
</tr>
<tr>
<td width="22%">Discount in <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo percent; ?>" checked="checked" onChange="show_record()" />% or <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo cash; ?>" onChange="show_record()" />Cash</td>
<td width="38%"><input type="text" class="input_text" name="concession" id="concession" value="<?php if($_POST['concession']) echo $_POST['concession']; else if($row_record['discount'] !=0) echo $row_record['discount']; else echo 0; ?>" onBlur="show_record()"/>
</td>
<td width="40%"></td>
</tr>
</table>
<input type="submit" value="Save Record" name="save_changes" />
</form>
PHP CODE FOR SAVE IN DB
if(isset($_POST['save_changes']))
{
$total_fees=($_POST['total_fees']) ? $_POST['total_fees'] : "0";
$data_record['total_fees']=$total_fees;
$courses_id=$db->query_insert("enroll", $data_record);
}
<?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 ?
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 working on an existing application. I am encountering a strang issue. Here is my loop.
<tbody>
<?php if($results->num_rows > 0 ): ?>
<?php foreach ($results->result() as $row1): ?>
<tr>
<td class="td_data"><?php echo $row1->customer_name; ?></td>
<td class="td_data"><?php echo $row1->postcode; ?> </td>
<td class="td_data"><?php echo $row1->company; ?></td>
<td class="td_data"><?php echo $row1->enquiry_status; ?></td>
<td class="td_data"><?php echo $row1->form_source; ?></td>
<td class="td_data"><?php echo anchor('customer/edit/' . $row1->customer_id, 'Edit'); ?></td>
<td class="td_data">
Login
<?php $action = $this->config->item('front_site_url').'members/login';?>
<form id="member_login<?php echo $row1->customer_id?>" action="<?php echo $action;?>" method="post" >
<input type="hidden" name="username" value="<?php echo $row1->username?>"/>
<input type="hidden" name="password" value="<?php echo $row1->password?>"/>
<input type="hidden" name="submitted" value="yes" />
</form>
<script type="text/javascript">
$('#member_login_link<?php echo $row1->customer_id?>').click(function(){
$('#member_login<?php echo $row1->customer_id?>').submit();
});
</script>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td class="td_data">No Record Found</td>
</tr>
<?php endif; ?>
</tbody>
This creates a list. And inspecting element displays this.
Here is the result of firebug which is fine on all the elements except the first.
And here is the first row result
I am unable to understand why this is happening. I have checked on different browsers and all have same issue.
EDITS:
This list that is being generate has form in each row. clicking on Login opens a tabs and asks for username and password. But the first row does not have form tags so it is not opening tag.
I have found the issue. A form closing tag was not written in header for Search functionality. so it was picking the first form closing tag and the form opening tag in the list was left to be hanged so it was not working.
Use empty form tag before main form tag inside foreach loop, then first empty form tag will be removed by foreach loop and functionality will work fine.
For example:
<div>
<form></form>
<form id="member_login<?php echo $row1->customer_id?>" action="<?php echo $action;?>" method="post" >
<input type="hidden" name="username" value="<?php echo $row1->username?>"/>
<input type="hidden" name="password" value="<?php echo $row1->password?>"/>
<input type="hidden" name="submitted" value="yes" />
</form>
</div>