CodeIgniter form_validation and form_error - delete original error message - codeigniter-3

I'm using CodeIgniter form_validation and
Everything works good except the original notification still appears in the top right.
Can anybody advise me how to delete the original notification?
I've inserted the PHP code into to view page.
<?php echo form_error('uname'); ?>
The form_error message appears the way I want but the original error message still appears in the top right, and I don't know how to delete that.
EDIT 01/08/19
Below is edited coding I've taken from the CI UserGuide.
Controller
<?php
class Form extends CI_Controller
{
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required', array('required' => 'You must provide a %s.'));
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
View
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<div><input type="submit" value="Submit" /></div></form>
</body>
</html>
If the above is loaded the result will be the Username Text Box in the top left corner, and the Password Text Box below it.
If the Submit button is clicked without any content in the text boxes the following notifications appear in the top left corner and above the Text Boxes.
You must provide a Username.
You must provide a Password.
However, if I change the view page to the following, the same notifications STILL APPEAR IN THE TOP LEFT CORNER, as well as next to the Text Boxes, so in effect each notification appears twice.
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<?php echo form_error('username'); ?>
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<?php echo form_error('password'); ?>
<div><input type="submit" value="Submit" /></div></form>
</body>
</html>
It is the notifications that still appear in the top left corner, that I want to delete.
I can't find any coding that positions the notifications so I guess that comes from somewhere within the CI system.
I can position the form_error notifications by using css coding.

I found the problem.
<?php echo form_error('username'); ?> // When this is inserted.
<?php echo validation_errors(); ?> //This must be deleted.
Or put another way the coding above provides the notifications at the top right.

Related

Register membership after custom payment gateway

Hi I am trying to somehow create a custom payment gateway. The one I am using is integrated in Gravity Forms and I have created a new php gateway MeprTransactiumGateway.php to include this new custom gateway.
I am able to capture the payment but not assign the subscription to the member. The member is being registered in memberpress but with no Memberships.
This is the code I am editing:
public function display_payment_form($amount, $user, $product_id, $txn_id) {
$mepr_options = MeprOptions::fetch();
$prd = new MeprProduct($product_id);
$coupon = false;
$txn = new MeprTransaction($txn_id);
//Artifically set the price of the $prd in case a coupon was used
if($prd->price != $amount) {
$coupon = true;
$prd->price = $amount;
}
ob_start();
$invoice = MeprTransactionsHelper::get_invoice($txn);
//echo $invoice;
$email = MeprTransactionsHelper::get_email($txn);
echo do_shortcode("[gravityform id=\"4\" field_values=\"email=".$email."\" title=\"Subscription\" description=\"false\" ajax=\"true\"]");
/* ?>
<div class="mp_wrapper mp_payment_form_wrapper">
<form action="" method="post" id="payment-form" class="mepr-form" novalidate>
<input type="hidden" name="mepr_process_payment_form" value="Y" />
<input type="hidden" name="mepr_transaction_id" value="<?php echo $txn_id; ?>" />
<div class="mepr_spacer"> </div>
<input type="submit" class="mepr-submit" value="<?php _e('Submit', 'memberpress'); ?>" />
<img src="<?php echo admin_url('images/loading.gif'); ?>" alt="<?php _e('Loading...', 'memberpress'); ?>" style="display: none;" class="mepr-loading-gif" />
<?php MeprView::render('/shared/has_errors', get_defined_vars()); ?>
<noscript><p class="mepr_nojs"><?php _e('Javascript is disabled in your browser. You will not be able to complete your purchase until you either enable JavaScript in your browser, or switch to a browser that supports it.', 'memberpress'); ?></p></noscript>
</form>
</div>
<?php*/
}
The gravity form is being echoed using do_shortcode. The payment is going through. Then a success or fail message is displayed as confirmation. I would like that if a success message is received the membership is actually submitted (this was previously done in the html form code that is commented out)

inserting text box input into URL parameter without GET method

In this form I want to get the value of the text box Enter Techs name: in to the URL but my form method is post.So that my url would look like
http://localhost/cs_3/index.php?page=chat&tech=
Is there any way I could do it.Can't use get method because I don't want the message to be seen in the URL.
<form method="post" >
<label>Enter Username:<input type="text" name="sender"/></label>
<?php if($user['Level'] == 3){?>
<label>Enter Clients name:<input type="text" name="tech"/></label>
<?php }else{ ?>
<label>Enter Techs name:<input type="text" name="tech" /></label>
<?php } ?>
<label>Enter Message:<textarea name="message" rows="8" cols="70"></textarea></label>
<div id="submit"><input type="submit" name="send" value="Send Message"></div>
</form>
You may use action param at your form.
Change it on key press in tech input by javascript (easy with jquery).

Contact page template - redirect to 'thank you page' not working

I'm trying to submit a form via custom page template but the problem is that it only works with form action="<?php the_permalink() ?>" and I need the form to be submitted and redirected to something like this form action="<?php bloginfo('url')?>/message-sent?id=<?php the_ID() ?>"
Full code:
<?php
$emailError = '';
if(isset($_POST['submitted'])) {
$email = trim($_POST['email']);
//setup self email address
$emailTo = $email;
$subject = "[reminder] Don't forget to download " . get_the_title();
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: Myemail reminders <no-reply#xyz.com>' . "\r\n";
wp_mail($emailTo, $subject, $body, $headers);
$emailSent = true;
} ?>
<section class="box grid_9 list_posts">
<div class="inner">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="entry-content">
<div class="contact-form clearfix">
<?php if(isset($emailSent) && $emailSent == true) { ?>
<div class="thanks">
<?php _e('Thanks, your email was sent successfully.', 'framework') ?>
</div>
<?php } else { ?>
<?php the_content(); ?>
<?php if(isset($hasError) || isset($captchaError)) { ?>
<p class="error"><?php _e('Sorry, an error occured.', 'framework') ?>
<?php } ?>
<form action="<?php the_permalink()?>" id="contactForm" method="post">
<ul class="contactform">
<li>
<input type="email" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="required requiredField email" required="required" />
</li>
<li class="buttons">
<input type="hidden" name="submitted" id="submitted" value="true" />
<input type="submit" value="Remind Me!"></input>
</li>
</ul></form>
<?php } ?></div>
</div>
</div>
<?php endwhile; else: ?>
<div id="post-0" <?php post_class() ?>>
<h1 class="entry-title"><?php _e('Error 404 - Not Found', 'framework') ?></h1>
</div>
<?php endif; ?></div>
</section>
I got no php errors in log, page is redirected successfully, but no email is sent. When using the_permalink, everything works just fine.
When submitting the form data to a different script, make sure the code for (validating the input and) sending the email is in that very file.
Otherwise, your URL /message-sent might rewrite to a completely different script and the script with the above code isn't involved at all once the submit button gets clicked.
Did that held you? Feel free, to ask, if my wording is incomprehensible or if my description isn't clear to you
Maybe you forgot to put ".php" at the end of your /message-sent?id=xxx file, i.e /message-sent.php?id=xxx?
Another thought: It is always a good idea to filter the user input, because you will receive a lot of spam, put some sort of CAPTCHA validation code and sanitize/validate the whole user input text, i.e. every text, which comes from input fields of your form.
For email:
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
For name and comments:
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$comments = filter_var(strip_tags($_POST['comments']), FILTER_SANITIZE_STRING);

Buddypress custom avatar upload page

I'm hoping someone on this forum can help me with a custom avatar upload page I'm trying to create for Buddypress. Apologies in advance for the long email, but I want to be as clear as possible so I can hopefully get a clear and specific answer :)
The page is part of a three step "getting started" process the user completes after registering for the website (1. filling out profile fields 2. uploading avatar 3. inviting friends).
I'm no expert with code, but I have got step 1 and 3 sorted by copying and editing the code from the profile/edit.php and invite-anyone/by-email/by-email.php files respectively, and then doing a redirect onsubmit to the next step.
To get step 1 to work I also had to edit the bp-xprofile-template.php file to include an if is_page ... else ... so that the page would use loggedin_user rather than displayed_user.
With step 2 I have the page appearing correctly, but after I choose an image for the avatar and hit upload the page refreshes and does not go to the crop, which is what it would do if you were uploading an avatar on the change-avatar page within the profile.
If I change the form action to redirect to the change-avatar page within the logged in user profile (by default there is no action), then the crop appears, but I don't want to have the user leave the "steps".
I thought maybe I needed to change something in the set of avatar_admin functions in bp-core-template.php so that it will work on other pages, but this is no beyond my abilities. I really hope someone can help with this because it is the final hurdle for completing this process.
Below is the code for the change-avatar.php and this is what I've copied and am trying to make work on a custom page. My page stops working properly at "if ( 'crop-image' == bp_get_avatar_admin_step()". Thanks in advance.
<h4><?php _e( 'Change Avatar', 'buddypress' ) ?></h4>
<?php do_action( 'bp_before_profile_avatar_upload_content' ) ?>
<?php if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?>
<p><?php _e( 'Your avatar will be used on your profile and throughout the site. If there is a Gravatar associated with your account email we will use that, or you can upload an image from your computer.', 'buddypress') ?></p>
<form action="" method="post" id="avatar-upload-form" class="standard-form" enctype="multipart/form-data">
<?php if ( 'upload-image' == bp_get_avatar_admin_step() ) : ?>
<?php wp_nonce_field( 'bp_avatar_upload' ) ?>
<p><?php _e( 'Click below to select a JPG, GIF or PNG format photo from your computer and then click \'Upload Image\' to proceed.', 'buddypress' ) ?></p>
<p id="avatar-upload">
<input type="file" name="file" id="file" />
<input type="submit" name="upload" id="upload" value="<?php _e( 'Upload Image', 'buddypress' ) ?>" />
<input type="hidden" name="action" id="action" value="bp_avatar_upload" />
</p>
<?php if ( bp_get_user_has_avatar() ) : ?>
<p><?php _e( "If you'd like to delete your current avatar but not upload a new one, please use the delete avatar button.", 'buddypress' ) ?></p>
<p><a class="button edit" href="<?php bp_avatar_delete_link() ?>" title="<?php _e( 'Delete Avatar', 'buddypress' ) ?>"><?php _e( 'Delete My Avatar', 'buddypress' ) ?></a></p>
<?php endif; ?>
<?php endif; ?>
<?php if ( 'crop-image' == bp_get_avatar_admin_step() ) : ?>
<h5><?php _e( 'Crop Your New Avatar', 'buddypress' ) ?></h5>
<img src="<?php bp_avatar_to_crop() ?>" id="avatar-to-crop" class="avatar" alt="<?php _e( 'Avatar to crop', 'buddypress' ) ?>" />
<div id="avatar-crop-pane">
<img src="<?php bp_avatar_to_crop() ?>" id="avatar-crop-preview" class="avatar" alt="<?php _e( 'Avatar preview', 'buddypress' ) ?>" />
</div>
<input type="submit" name="avatar-crop-submit" id="avatar-crop-submit" value="<?php _e( 'Crop Image', 'buddypress' ) ?>" />
<input type="hidden" name="image_src" id="image_src" value="<?php bp_avatar_to_crop_src() ?>" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<?php wp_nonce_field( 'bp_avatar_cropstore' ) ?>
<?php endif; ?>
</form>
<?php else : ?>
<p><?php _e( 'Your avatar will be used on your profile and throughout the site. To change your avatar, please create an account with Gravatar using the same email address as you used to register with this site.', 'buddypress' ) ?></p>
<?php endif; ?>
<?php do_action( 'bp_after_profile_avatar_upload_content' ) ?>
My page stops working properly at "if ( 'crop-image' == bp_get_avatar_admin_step()"
So what does bp_get_avatar_admin_step() = at that point ?
Echo it out to see.
Does the avatar actually upload?
If so, you have to figure out how to advance the admin_step.
I thought maybe I needed to change something in the set of avatar_admin functions in bp-core-template.php, but this is no beyond my abilities
Rather than change, figure out how they are called.
I just finished working on implementing my own custom avatar page and had the same issue. I think I actually have lost hair over it. haha. I ended up adapting the code on my end to ensure that bp can still be upgraded by taking a few chunks of the relevant code and building it into a new function in as part of my theme.
The problem is the hidden submit value 'w' is one of many reserved wordpress terms.
<input type="hidden" name="image_src" id="image_src" value="<?php bp_avatar_to_crop_src(); ?>" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
You will need to change this value to anything other and then implement your own version of the handler function:
buddypress/bp-xprofile/bp-xprofile-screens.php->xprofile_screen_change_avatar();
Also, perhaps there's a better way, but for the cropping to work I had to implement a separate call for the content within the
bp_core_add_jquery_cropper(){
wp_enqueue_style( 'jcrop' );
wp_enqueue_script( 'jcrop', array( 'jquery' ) );
add_action( 'wp_head', 'bp_core_add_cropper_inline_js' );
add_action( 'wp_head', 'bp_core_add_cropper_inline_css' );
}
to
wp_enqueue_style( 'jcrop' );
wp_enqueue_script( 'jcrop', array( 'jquery' ) );
add_action( 'wp_footer', 'bp_core_add_cropper_inline_js' );
add_action( 'wp_footer', 'bp_core_add_cropper_inline_css' );
within my own implementation of the profile_screen_change_avatar().
Hopefully, this can still be some use to you or others. Let me know if this all makes sense (well or doesn't ;) ).
Thank you for your helpful suggestions. Just to add that #Zenvied's suggestions work very well. The only thing is I had to add my own implementations of "bp_core_add_cropper_inline_js()" and "bp_core_add_cropper_inline_css()" and then call them from within my implementation of "xprofile_screen_change_avatar()". So instead of this:
wp_enqueue_style( 'jcrop' );
wp_enqueue_script( 'jcrop', array( 'jquery' ) );
add_action( 'wp_footer', 'bp_core_add_cropper_inline_js' );
add_action( 'wp_footer', 'bp_core_add_cropper_inline_css' );
I did this:
self::bp_custom_core_add_cropper_inline_css();
self::bp_custom_core_add_cropper_inline_js();
wp_enqueue_style( 'jcrop' );
wp_enqueue_script( 'jcrop', array( 'jquery' ) );
Hope this helps someone! :-)

image submit button

I am trying to update records with a image button. here is my code:
<?php
if(isset($_POST['unstar'])) {
echo "good!";
}
?>
<form action='' method='post'>
<input type='image' src='http://mysite.com/images/starIcon.png' name='unstar' id='unstar' />
</form>
When I click on the image, it does not echo "good". what am I doing wrong?
I just tested your code and apparently when you click on the image button, php generates the following post values unstar_x and unstar_y, both of which correspond to the x and y coordinates of where you clicked the button.
Try changing it to the following and you'll see what I mean:
<?php
print_r($_POST);
?>
<form action='' method='post'>
<input type='image' src='http://mysite.com/images/starIcon.png' name='unstar' id='unstar' />
</form>
EDIT
So if you just need to see if the button was pressed to submit the form, you can just do the following, which just checks if unstar_x or unstar_y was set.
<?php
print_r($_POST);
if(isset($_POST['unstar_x']) || isset($_POST['unstar_y'])){
echo "Good";
}
?>
<form action='' method='post'>
<input type='image' src='http://mysite.com/images/starIcon.png' name='unstar' id='unstar' value="testing" />
</form>
You should note that the output of $_POST will not include the value Testing. At least on my system, I don't get a value when I submit the image button.
The problem is that you're not giving unstar a value, so it won't be detected as Set by the function.