Codeigniter text area validation rule doesn't work - php

I am trying to validate text area in codeigniter
code in view
Write the best two hoppy you pratise
<?php $user=" "; ?>
<form action= "<?php echo base_url('log_c/save_hoppy/ ' .$user ); ?>" method="post" >
<?php echo form_error('hoppy'); ?>
<textarea name="hoppy" cols="20" rows="2">
<?php echo set_value('hoppy'); ?>
</textarea>
<input type="submit" name="submitbutton" value=" Save ">
</form>
and this code in controller
public function save_hoppy($user)
{
$this->form_validation->set_rules('hoppy', 'Hoppy', 'required|max_length[40]');
echo"after validation".$user."<br>";
$hoppy = $this->input->post('hoppy');
echo"<br>this hoppy".$hoppy;
}
But this validation doesn't work
.the population text area work please any one help me

remove above text area and paste Codeigniter form input
$data = array(
'name' => 'hoppy',
'id' => 'hoppy',
'rows' => '2',
'cols' => '20',
'maxlength' => '40'
);
echo form_textarea($data);

Here is the solution
<textarea name="description">
<?php echo set_value('description'); ?>
</textarea>

Related

wordpress admin panel get parameter

I'm developing a plugin in wordpress, there is data that needs to be listed by search but I can't get them with the get parameter.
I can send with the post parameter, but when the user refreshes the page, she has to search again according to the order number.
Following my code:functions.php
add_action('admin_menu', 'testPluginAdminMenu');
function testPluginAdminMenu()
{
add_menu_page('Return Request',
'Return Request',
'manage_options',
'list',
'myFunction'
);
add_submenu_page(
'null',
'Return Request List',
'Return Request List',
'manage_options',
'listAll',
'myFunctionList');
}
index.php
<?php
function myFunctionList(){
if(isset($_GET['request_order'])){
echo $search = $_GET['request_order'];
}
}
function myFunction(){ ?>
<form method="get" action="<?php echo admin_url('admin.php?page=listAll&request_order='.$_GET['request_order'] ) ?>">
<input type="text" name="request_order" placeholder="Search Order Number..">
<button type="submit" >Search</button>
</form>
<?php } ?>
Output from url: localhost/wordpress/wp-admin/admin.php?request_order=7481
page=listAll not appearing on url
Thank you advance.
Can you try something like this
$qs = array(
'page' => 'listAll',
'request_order' => $_GET['request_order']
);
$qs = http_build_query($qs, null, "&", PHP_QUERY_RFC3986);
<?php echo admin_url('admin.php?' . $qs ) ?>
UPDATE 1
<form method="get" action="<?php echo admin_url('admin.php?page=listAll&request_order='.$_GET['request_order'] ) ?>">
<input type="text" name="request_order" placeholder="Search Order Number..">
<input type="hidden" name="page" value="listAll" />
<button type="submit" >Search</button>
</form>

Why is my form not being submitted?

I have 2 functions - one generates the form on my main page and the other processes the submitted form. This is the Braintree sandbox API and their method is this: take in user info and submit to Braintree server, BT server returns a payment method nonce to me which I can then use to POST and view the transaction in my sandbox control panel. However, the form isn't being submitted and I'm not sure at what point in the process the whole submission is failing. NOTE - I am submitting the form to the same PHP file where the form is located.
I still need help on this...
ask.php - This is the page where I call both functions
<div>
<?php
fd_bt_form();
fd_process_trans();
?>
</div>
find-do-for-anspress.php
$FD_Braintree_Keys = array(
Braintree_Configuration::environment('sandbox'),
Braintree_Configuration::merchantId('A'),
Braintree_Configuration::publicKey('B'),
Braintree_Configuration::privateKey('C')
);
function fd_bt_form()
{
$class_bt_token = new Braintree_ClientToken();
$clientToken = $class_bt_token->generate();
?>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<script>
braintree.setup(
'<?php echo $clientToken ?>',
'custom', {
id: 'checkout',
});
</script>
<?php
echo
'<form id="checkout" action="" method="POST">
<p>
<label><font size="5">Amount:</font></label>
<input type="text" size="4" name="amount" id="amount" />
</p>
<input data-braintree-name="number" value="378282246310005">
<br> <br />
<input data-braintree-name="expiration_month" value="05">
<input data-braintree-name="expiration_year" value="17">
<br> <br />
<input data-braintree-name="cvv" value="531">
<br> <br />
<input type="submit" id="submit" value="Pay">
</form>';
echo $_POST["payment_method_nonce"];
global $bt_nonce;
$bt_nonce = $_POST["payment_method_nonce"];
return $bt_nonce;
}
function fd_process_trans() {
$FD_Braintree_Keys;
$nonce = $_POST["payment_method_nonce"];
$amount = $_POST["amount"];
$result = Braintree_Transaction::sale(array(
'amount' => $amount,
'paymentMethodNonce' => $nonce,
'options' => array(
'submitForSettlement' => True,
),
));
if ($result->success) {
echo "Success!";
}
else {
echo "Transaction failed.";
}
}

Updating different forms at the same time

Current Situation
So, this is a follow up question from my previous question (Submit button to affect multiple files)
The approach was good in terms of how to "click" multiple buttons together by using a "super-button" (patent pending) by #oMiKeY. It does what it is supposed to do, clicking all buttons.
The mark up is the following:
Title.php
<form role="form" method="post">
<div class="edit_title">
<input type="hidden" value="<?php echo $post_id; ?>">
<?php post_input_box( $post_id, 'post_title', array( 'placeholder' => 'Article title..', 'value' => $post->post_title ) ); ?>
<div class="update-button-wrap">
<input id="save_button" type="submit" name="update_product" value="<?php esc_attr_e( 'Update', 'site' ); ?>"/>
</div>
</div>
</form>
Content.php
<form role="form" method="post">
<div class="edit_content">
<?php post_input_box( $post_id, 'post_content', array( 'placeholder' => 'Short description..', 'value' => $post->post_content ), 'textarea' ); ?>
</div>
<div class="update-button-wrap">
<input id="save_button" type="submit" name="update_product" value="<?php esc_attr_e( 'Update', 'site' ); ?>"/>
</div>
</form>
Article.php
<button type='button' onclick="$('[type="submit"]').click()">Submit</button>
Problem
So, when the "Submit" button is clicked, both buttons in each title.php and content.php are also clicked (ie. in regards to clicking buttons, it works fine). However, because two forms are simultaneously clicked, only the second one is updated (either content or title) while the first one is ignored, when both data are needed to be updated.
My approach
Now, I can merge two files together and have both title and content within a single form, but that really messes up my overall setup and I heard it is better to have multiple smaller php files for updating and speed than a large one big file.
Or here is my another approach.
In the article.php, I will have the form and submit button while the title.php and content.php only has the editable forms. Then these two forms are somehow linked to the form in article.php, like the image below.
Do you think the second approach can be achieved or any other suggestions?
Thanks
Just add a global form on article.php and drop the title and content forms (and submit buttons). Every named input inside the global form will be submitted together no matter what php file generated them.
Edit:
Title.php
<div class="edit_title">
<input type="hidden" value="<?php echo $post_id; ?>">
<?php post_input_box( $post_id, 'post_title', array( 'placeholder' => 'Article title..', 'value' => $post->post_title ) ); ?>
</div>
Content.php
<div class="edit_content">
<?php post_input_box( $post_id, 'post_content', array( 'placeholder' => 'Short description..', 'value' => $post->post_content ), 'textarea' ); ?>
</div>
Article.php
<form role="form" method="post">
<?php include "Title.php"; include "Content.php"; ?>
<button type='submit'>Submit</button>
</form>
Option 2:
Alternatively you could use some sort of functionality that allows you to create forms only once, even if you have "inner forms". This way Title.php and Content.php would also work as standalone code snippets.
$formDeep = 0;
function openForm() {
global $formDeep;
if ($formDeep == 0) {
echo "<form role=\"form\" method=\"post\">";
}
$formDeep++;
}
function closeForm() {
global $formDeep;
$formDeep--;
if ($formDeep == 0) {
echo "</form>";
}
}
Title.php
<?php openForm(); ?>
<div class="edit_title">
<input type="hidden" value="<?php echo $post_id; ?>">
<?php post_input_box( $post_id, 'post_title', array( 'placeholder' => 'Article title..', 'value' => $post->post_title ) ); ?>
</div>
<?php closeForm(); ?>
Content.php
<?php openForm(); ?>
<div class="edit_content">
<?php post_input_box( $post_id, 'post_content', array( 'placeholder' => 'Short description..', 'value' => $post->post_content ), 'textarea' ); ?>
</div>
<?php closeForm(); ?>
Article.php
<?php openForm(); ?>
<?php include "Title.php"; include "Content.php"; ?>
<button type='submit'>Submit</button>
<?php closeForm(); ?>

codeigniter post html textarea

when i try to post html from my textarea the variable value is empty and form_validation show error message that the input is required......
i search for solution and i didn't found ....
this is my code
<form accept-charset="utf-8" method="post" action="<?php echo base_url('send_message/validate'); ?>">
<?php
echo validation_errors();
echo form_dropdown('cat_name', $plan_cat);
?>
<div>
<span><label>اسم الراسل باللغه الانجليزية</label></span>
<span><input name="from" type="text" class="textbox" value="<?php echo set_value('from'); ?>" /></span>
</div>
<div>
<span><label>العنوان</label></span>
<span><input name="subject" type="text" class="textbox" value="<?php echo set_value('subject'); ?>" /></span>
</div>
<div>
<span><label>الرساله</label></span>
<?php
/*
$options = array(
'name' => 'message',
'id' => 'elm1'
);
echo form_textarea($options);
*/
?>
<textarea name="message" id="elm1"><?php echo set_value('message'); ?></textarea>
</div>
<div>
<span><input type="submit" value="ارسل" /></span>
</div>
<?php
echo form_close();
?>
and this is my controller code :
$this->load->library('form_validation');
$this->form_validation->set_rules('from', 'الراسل', 'required|min_length[8]');
$this->form_validation->set_rules('subject', 'عنوان الرساله', 'required|min_length[6]');
$this->form_validation->set_rules('message', 'الرساله', 'trim|required|min_length[10]|xss_clean');
if($this->form_validation->run() == false){
$user_id = $this->session->userdata('user_id');
$send = array(
'title' => 'ارسل الرساله',
'plan' => $this->user_plan->get_plan($user_id)
);
$this->load->library('parser');
$this->parser->parse('header', $send);
$this->parser->parse('send_message', $send);
$this->parser->parse('footer', $send);
}else{
$user_id = $this->session->userdata('user_id');
$plan_cat = $this->input->post('cat_name');
$from = $this->input->post('from', true);
$subject = $this->input->post('subject', true);
$message = $this->input->post('message', true);
$message = '<code>'.$message.'</code>';
i hope to find way to solve this :)
First , before going deep in your code , I have to say that : using base_url functionality as action attribute is bad. You have to use site_url instead in this way :
echo site_url('send_message/validate');
The reason stands behind that :
site_url gives you the full URL including the main processing file (index.php) which is important to handle your MVC requests (e.g http://domain.com/codeigniter/index.php/send_message/validate)
base_ur gives you the URL without any consideration for the main file (index.php) (e.g http://domain.com/codeigniter/send_message/validate)
Second (And the important). I see that you are using XSS Filter for the (message) which means you are trying to put illegal content in the textarea. Try to put anything else everything will be ok.
So , make sure that your message value doesn't contain illegal characters.

get data from text area and post to a wall onfacebook

not sure if this is possible, but what i need to do is take the data from my text area and let the user post that to their wall.
my code snippet
<div align="center">
<form method="GET" action="translate.php">
<textarea name="status2" cols="50" rows="5"<input type="text"/>
<?php echo str_ireplace(array ('old','awkward','all','again','behind','along','alright','hello','among','children','yes','child','kids','food','barnard castle','beer','book','blow','beautiful','bird','burst','brown','burn','boots'),
array ('auld', 'aakwad', 'aall','agyen','ahint','alang','alreet','alreet','amang','bairns','aye','bairn','bairns','bait','barney','beor','beuk','blaa','bonny','bord','borst','broon','bourn','byeuts'),$status); ?>
</textarea><br>
<input type="submit" value="post to wall" />
</form>
</div>
<?php
$args = array(
'message' => 'Hello World',
'link' => 'http://apps.facebook.com/geordie-status/',
'caption' => 'Translate from English to Geordie'
);
$post_id = $facebook->api("/$uid/feed", "post", $args);
?>
the default message 'Hello World' posts to the wall, but i would like to replace that with the text in 'status2' text area. Is this possible?
Thanks
<textarea name="status2" cols="50" rows="5"<input type="text"/>
Doesn't make sense.
Guessing that your textarea is well coded in your real snippet. You should have the value of the textarea inside $_GET['status2'], so change traslate.php:
$args = array(
'message' => $_GET['status2']
...
this is the code i've written for the test:
index.html
<form method="GET" action="server.php">
<textarea name="status2"></textarea>
<input type="submit" value="go"/>
</form>
server.php
<?
print_r($_GET);
?>

Categories