I am learning word press. I have 2 questions
I have created a page and assigned my template file for it.
1. Question
How to get my form input values in same page or in another page template?
<form id="formId" action="" method="post">
<input style="width:88%" type="text" name="name">
<input type="submit" name="subs" value="Submit" />
</form>
In same file I put:
<?php
if( isset($_POST['subs']) ) {
echo $_POST['name'];
}
?>
I also tried $_SERVER['PHP_SELF']; in action but it's not displayed.
How could I store it in my own table?
When click submit, it refreshes and displays "No Results Found".
2. Question
How to show the submitted values in wp-admin?
Here's the word press code flow I can't solve.
Change Form action to the same page:
<form action="<?php the_permalink(); ?>
try to use
action="<?php echo get_permalink(); ?>"
instead of
action="<?php echo $_SERVER['PHP_SELF']; ?>"
in your form
Related
I'm using CakePHP 3.4
I have a form with two submit buttons like
<?= $this->Form->create($post) ?>
<?= $this->Form->control('title') ?>
<button name="submit_type" value="draft" type="submit">Draft</button>
<button name="submit_type" value="publish" type="submit">Publish</button>
<?= $this->Form->end() ?>
According to w3schools button value is also sent to server.
But when I debug
debug($this->request->getData('submit_type'));
it gives NULL. Also debugging getData(), it gives only title field.
How to get value of submit button?
I had the same problem. Try to use "input type" instead of "button", like
<input name="submit_type" value="Draft" type="submit" />
<input name="submit_type" value="publish" type="submit"/>
Hope, this will help you. :)
Sorry I am new to WordPress and still having difficulty to retrieve my data from my custom database. So far this is my code for submitting data to my wp_datareg table.
<?php
/*
Template Name: Data-Register
*/
get_header();
?>
<?php
If($_POST['Submit']) {
global $wpdb;
$Data1=$_POST['Data1'];
$Data2=$_POST['Data2'];
if($wpdb->insert(
'wp_datareg',
array(
'Data1' => $Data1,
'Data2' => $Data2
)
) == false) wp_die('Database Insertion Failed');
else echo '<h2>Database Insertion Succesful</h2><p />';
?>
<?php
}
else // else we didn't submit the form so display the form
{
?>
<
<h4>Data Registration Form</h4>
<form action="" method="post" id="addcourse">
<p><label>Put Data1:<input type="text" name="Data1" size="30" /></label></p>
<p><label>Put Data2: <input type="text" name="Data2" size="30" /></label></p>
</div>
<input type="submit" name="Submit" id="addcoursesubmit" value="Submit" />
</form>
What I want to add is put another text form and search button where user can search a data of Data1 and edit its value on the form, (please see the image)
Sorry for being such a noob.
PLEASE SEE THIS IMAGE
Thank you.
br
We can fetch data from wp_datareg table using this code, however putting back the data to the form is my problem.
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM wp_datareg" );
foreach ( $result as $print ) {
?>
<tr>
<td><?php echo $print->Data1;?></td>
</tr>
I have this form:
<div id="buscador">
<form action="<?php echo Router::url(array('controller'=>'categorias','action'=>'buscar'));?>" name="form_search" id="form_search" method="post" >
<input type="text" name="search">
<input type="submit" value="Buscar" class="buscador" id="boton_buscar"/>
</form>
</div>
It works fine in all controllers except when you are using the controller "categorias"... in that case, the result is this: http....Categorias/buscar/Buscar
Any idea why this happens?
The problem was present elsewhere, I didn't consider that when clicking the button inside the View "buscar", then JS acts on that click (and this generates the buscar/Buscar problem)
Hello everyone,
I am new to paypal but now the basics of cakephp, rightnow I am making a paypal integration with cakephp but unable to pass the value to the paypal. I'm showing you my code. Please tell me if I'm doing something wrong.
function paypal()
{
if($this->request->is('post'))
{
echo $item_name_1=$this->request->data['Choose']['item_name_1'];
echo"<br>";
echo $amount_1=$this->request->data['Choose']['amount_1'];echo"<br>";
echo $item_name_2=$this->request->data['Choose']['item_name_2'];echo"<br>";
echo $amount_2=$this->request->data['Choose']['amount_2'];echo"<br>";
echo $cmd=$this->request->data['Choose']['cmd'];echo"<br>";
echo $business=$this->request->data['Choose']['business'];echo"<br>";
echo $upload=$this->request->data['Choose']['upload'];echo"<br>";
echo $currency_code=$this->request->data['Choose']['currency_code'];echo"<br>";
echo $item_number_1=$this->request->data['Choose']['item_number_1'];echo"<br>";
echo $item_number_2=$this->request->data['Choose']['item_number_2'];echo"<br>";
$this->redirect('https://www.paypal.com/cgi-bin/webscr?cmd='.$cmd.'&upload='.$upload.'&business='.$business.
'¤cy_code='.$currency_code.'&item_number_1='.$item_number_1.'&item_name_1='.$item_name_1.
'&'.'amount_1='.$amount_1.'&item_number_2='.$item_number_2.'&item_name_2='.$item_name_2.'&'.'amount_2='.$amount_2);
}
}
I'm passing all the view values(including hidden fields) to my controller(all values are displaying correctly) and redirecting it to the paypal site. Here I'm sending multiple values but I'm getting error like this:
This recipient is currently unable to receive money.
If i write the same code in corephp then values are reaching to the paypal and everything working fine, please tell me where I'm getting wrong.
First off, you should prepare your code in the Controller:
function paypal(){
$this->set('paypalData', $this->request->data['Choose']);
}
... and then create a form (in a view) which is POSTed to the PayPal site:
//file: Views/ControllerName/paypal.ctp
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $paypalData['business']; ?>">
<input type="hidden" name="amount" value="<?php echo $paypalData['business']; ?>">
<input type="hidden" name="item_name_1" value="<?php echo $paypalData['item_name_1']; ?>">
<input type="hidden" name="item_number_1" value="<?php echo $paypalData['item_number_1']; ?>">
<input type="hidden" name="amount_1" value="<?php echo $paypalData['amount_1']; ?>">
<input type="hidden" name="currency_code" value="<?php echo $paypalData['currency_code']; ?>">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
The user would then click the button to go to PayPal, which is more reliable (and right :D). The url which you are redirecting to might fail in many ways, since your values are not url_encoded, might get too long, etc..
Second: Your error is probably popping up because you are using www.paypal.com instead of www.sandbox.paypal.com
Third: I copied the HTML above to ease the viewing, you should be using the Form helper inside the view to ensure proper HTML formatting.
Fourth: ECHOing inside a Controller action is just wrong. Especially so, if you are redirecting after making output. Redirects will not work if any output is sent to the browser.
Hope this gets you in the right direction.
I am learning CakePHP. I am trying to develop a login system, but instead of using the login.ctp as a user/view, I wish I could use it as a element because I have the login form in many other pages. How can I declare within my users_controller that my function login() will use just the element. I said that because I used $this->render('/elements/login') and it did work. However, my element login.ctp was within my default.ctp layout, thus, I had two login forms. One was the element and the other as my content in my default.ctp layout.
Thanks!
Layouts are for the "greater" markup of a page: head and meta information, includes, "footer" stuff like your analytics. Generic content pointers go in the middle - so there's no need to mark anything as specific as a form in a layout unless you really do want to include that form on every page that uses that layout.
It sounds like you either called $this->render() in your view? $this->render() is a controller method. $this->element is the view method.
Or you called $this->element('/elements/login'); from in your login.ctp view? That would mean the controlller rendered the default login.ctp view, which called the login.ctp element.
And thus you saw two. To fix:
To return something other than the default view associated with an action (such as your login snippet), call $this->render('name/of/whatever'); as the last line of the controller method. It will return the view you specify; set will pass whatever variables to it, just like a regular view call and if you want to get fancy, specify the layout as ajax and watch the magic start like $this->render('/elements/login', 'ajax').
If you need to call several elements in a single view file, use the method $this->element('/fancy/nav/whatever'); you can also place them in layouts as appropriate (navigation, etc.)
HTH. :)
I had the same thing done to my project and this is what I did.
Basically, I created a new loginElement.ctp and placed it in the element folder. I create new sets of HTML code that would fit the layout where I wanted to use this element and the loginElement.ctp <form would then submit the data to login action in the users_controller.
If you need to and when I get home later, I can post my exact code here.
==================================== EDIT =========================================
These are the codes I used:
First of all you will notice that the action in the login form points to /login.
I have that setup in my /config/routes.php file as such
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
Then the other codes are below
/views/elements/thinlogin.ctp
<div id="login">
<form method="post" action="/login" accept-charset="utf-8" class="formBox">
<fieldset>
<input type="hidden" name="_method" value="POST" />
<div class="form-col">
<label for="username" class="lab">Username/Email</label>
<input name="data[User][username]" type="text" id="UserUsername" class="input">
</div>
<div class="form-col form-col-right">
<label for="password" class="lab">Password</label>
<input type="password" name="data[User][password]" id="UserPassword" class="input">
</div>
<div class="form-col form-col-submit">
<input name="" value="Login" class="submit" type="submit">
</div>
<div class="form-col form-col-check">
<label><input name="remember" class="checkbox" type="checkbox">Remember me on this computer</label>
</div>
</fieldset>
</form>
</div>
/views/pages/home.ctp
<div id="home_top_right_top">
<?php
if (!$this->Session->check('Auth.User.id'))
{
echo $this->element('login/thinlogin');
}else{
echo $this->element('login/loggedin');
}
?>
</div>