I need to add a notification to this page saying " Thank you for your feedback"
However,the notification did not appear at the correct place,which is above the form.
This is my code.
$message="tq 4 feedback";
$common->display_message($message);
This is where the feedback form.
The function i'm using is
function display_message($message) {
print $message;
}
Thanks
Not sure why if you have the message already you are passing it to a function to display, but you need to "return" the variable from the function. Then you can echo it out wherever you need to.
function display_message($message) {
return $message;
}
To call it:
$message="tq 4 feedback";
$returned_message = $common->display_message($message);
And place it where you want:
echo $returned_message;
or just:
$message="tq 4 feedback";
echo $common->display_message($message);
It's probably an issue with your view, to be honest. What's your view look like?
Related
im trying to create a WordPress plugin for first time.
What i want from this plugin is really simple. I need to show form with 2 fields one for Subject second for message. Then take all registered users emails and use this data in wp_mail.
Then use short code soo i can display that form on front end. Just need to make possible send information imail to all registered users from front end.
Im trying this code:
if(isset($_POST['button1'])) {
showtext();
}
function show_form(){
echo ' <form method="post">
<input type="submit" name="button1" value="Button1"/>
</form>
';
}
function showtext(){
echo "text";
}
function group_email_shortcode() {
$odeslano=wp_mail( 'jindra.kos#seznam.cz', 'The subject', 'The message' );
if($odeslano) {
return "odeslano";
}//message sent!
else {
return "chyba";
}//message wasn't sent
}
add_shortcode( 'helloworld', 'show_form' );
If i call function for sending email in short code then it will send email and its working. When i try to call function where im showing form and from that form im calling function for sending email its not working and it shows me info about crytical error on page.. I have read a lots of stuffs, but i cant find any hint what im making wrong.
I have five unique forms each on a page of HTML. They then go to a PHP file to send the e-mail of data. Next they go to the HTML thank you page. I am hoping to change the heading according to which form they just submitted.
For example, if they submit a review, the should read "Thank you for your review" etc.
Technically all of these are saved as php files but only the e-mail page has php items.
Like <?php echo("<p>". $mail->getMessage()."</p>"); ?>
You should redirect to another php file and pass a parameter on url. Example:
sendemail.php
<?php
/** After send the email, check what kind form is (I don't know how do you check this).
This example is just to show you: */
if ($formType == 'review') {
$type = 'review';
} else if ($formType == 'anothertype') {
$type = 'anothertype';
}
header('Location: /thankspage.php?type=' . $type);
?>
thankspage.php
<?php
$type = $_GET['type'];
if ($type == 'review') {
echo '<h1>Thanks for your review</h1>';
} else if($type == 'anothertype') {
echo '<h1>Thanks for your anothertype</h1>';
}
?>
One way put a hidden field in your forms that'll get passed with the other form data. Then put an if statement on the thank you page and echo the appropriate message.
However, that'll only work either if you change the thank you page to php or change the page that receives and processes the form data to echo the thank you message as well
I have a form that is mostly generated by a class named "buildform".
Now every part of the form validates itself on the position it is.
This looks like this:
echo $frm->create_input("customer_nr", "Customer Nr.", "text:empty:int");
The third attribute here are the conditions (here: text field, not empty only integer).
The function "create_input" calls some more function that are validating the form field directly on place when the form is submitted.
I do it this way for multiple reasons:
I can directly color the forms to red when there's an error
I only have to tell the form attributes one time instead of when creating it and validating.
This is really comfortable and until now has made creating forms very easy.
The validation errors for then the users will be stored in a class variable like this:
function add_err($n_errmsg) {
$this->errmsgs[] = $n_errmsg;
return;
}
At the end of the form I show the errors like this:
if(isset($_POST["sbm"])) {
$ret_err = $frm->ret_err();
if(!empty($ret_err)) {
echo $ret_err;
}
else {
// send success mail
}
}
This all works without any problems.
Now I had the idea to hide the form when it's submitted. But then I would have to make sure there are no errors before the form even is loaded!
I wanted to something like
else {
$hideform = true;
// send success mail
}
This currently is not possible as the errors are generated while "generating" the form fields.
If I move the errors to the top the errors are always "empty" there because the validation is done later below...
Do you have an idea how I can solve this?
Do I have to validate the forms before loading them or is there another way?
Thanks!
Best Regards
Toby
Ok, well there are a few ways to solve this.
Basically you are echoing the form html as you go along:
echo $frm->create_input(...);
echo $frm->create_input(...);
what you could do instead is save the html into a string:
$formhtml = '';
$formhtml .= $frm->create_input(...);
$formhtml .= $frm->create_input(...);
if($frm->ret_error()){
echo $formhtml;
//other logic
}else{
//send mail
}
Along the same lines, you could change your form class, so that this is done internaly, and add a show method:
private $html = '';
function create_input(...){
//retrun $ret;
$this->html .= $ret;
function show(){
echo $this->html;
}
$frm->create_input(...);
$frm->create_input(...);
if($frm->ret_error()){
$frm->show();
//other logic
}else{
//send mail
}
I am making a website in CodeIgniter and for one of these pages I need to insert information into a database, however every time I enter information into my form and submit it, the page refreshes like it had been submitted but nothing enters the database.
Controller:
public function insertjob()
{
$this->load->helper('form');
$data['title']="Add a new job";
$this->load->view("insertjob", $data);
}
public function addingjob()
{
$jobtype=$this->input->post('jobtype');
$jobinfo=$this->input->post('jobinfo');
$this->load->model("cmodel");
if($this->cmodel->addjob($jobtype, $jobinfo)){
$data['msg']="New job addition successful";
}else{
$data['msg']="There was an error please try again";
}
$this->load->view("confirmation",$data);
Model:
function addjob($jobtype,$jobinfo)
{
$newjob=array("jobtype"=>$jobtype,"jobinfo"=>$jobinfo);
return $this->db->insert('clientjobs', $newjob); exit;
View:
</p>
<?php
echo form_open('client/insertjob');
echo form_label('Job:', 'Job');
echo form_input('jobtype');
echo form_label('Job information:', 'Job information');
echo form_input('jobinfo');
echo form_submit('Add job', 'Submit Post!');
echo form_close();
?>
Try removing the exit from your model:
function addjob($jobtype,$jobinfo)
{
$newjob=array("jobtype"=>$jobtype,"jobinfo"=>$jobinfo);
return $this->db->insert('clientjobs', $newjob);
}
It's not neccessary and could be breaking the database class, as well as halting any execution for the application.
Here's your problem:
echo form_open('client/insertjob');
If you look at your HTML code in your browser, you'll see something like this:
<form action="client/insertjob">
There will probably be a whole bunch of other attributes in your form tag - they're not important for this answer.
That action attribute is telling the browser where to go after you click submit. Where is it going? Back to the insertjob method. But it needs to go to your addingjob method - that's where the database update is actually being done. So change the form_open call to:
echo form_open('client/addingjob');
As I see your are using 2 controller functions for posting, page 1 to page 2. You have error on form open you should post your data to addingjob not insertjob.
echo form_open('client/addingjob');
will fix your issue but I highly recommend you to use, one controller for form submit. Below code will send post to same url. And you could add some attributes on it.
<?php
$attributes = array('class' => 'form-horizontal');
echo form_open($this->uri->uri_string(),$attributes); ?>
I need to insert some markup inside page based on whether a URL Query Var exists or not. I'm trying to insert the code inside a shortcode like so:
//Create Shortcode for join page error message
add_shortcode( 'join_error', 'av_join_error' );
function av_join_error(){
$joinresult = $_GET["result"];
if($joinresult){
echo "<p class='alert'>Your payment was declined. Please double check your details and try again.</p>";
}
}
It's not working, hopefully someone can point me in the right direction!
The code you posted is mostly fine, you will need to post more.
First do print_r($_GET) and make sure the array is actually being set.
Also, shortcodes should always return and not echo. Using return keeps the shortcode output where it is in the document/page (echo will output it to the top).
more about that here under Output: http://codex.wordpress.org/Shortcode_API
Try
//Create Shortcode for join page error message
function av_join_error(){
$joinresult = $_GET["result"];
if($joinresult){
echo "<p class='alert'>Your payment was declined. Please double check your details and try again.</p>";
}
}
add_shortcode( 'join_error', 'av_join_error' );