After a webform is submitted, I redirect it to its "webform result submission page" automatically.
Here all values are shown.
I want to access the values of that submission, to use them in some simple "if then" php statements.
This logic will add some text above that results page. (for example: if the submitted value of formelement_1 == 2 , then add this text "warning, formelement_1 has great value!").
Anybody some input ? Thanks
Try like this way
<?php
include_once(drupal_get_path('module', 'webform') .'/includes/webform.submissions.inc');
$nid = arg(1); // need to hard-code nid if this is a custom page
$sid = $_GET['sid'];
$submission = webform_get_submission($nid, $sid);
$first_name = $submission->data[1]['value'][0];
$last_name = $submission->data[2]['value'][0];
$thanks = $first_name . " " . $last_name;
?>
<h2>Thank you <?php print $thanks ?>... Your registration has been sent.</h2>
?>
I hope, it will works.
Related
I'm using Cakephp 3 with Cake\Network\Email\Email.
I have a form to send a message with two input fields. Those fields are stored in database.
I'd like to join an image to this form without storing it: only in attachment.
Here is my input file :
<?php echo $this->Form->file('photo', ['class' => 'form-control','value'=>'','accept'=>'image/*']); ?>
My Controller :
$Email = new Email('default');
$Email->theme('Front')
->template('my_template1')
->viewVars(['sender'=> $user, 'recipes'=> $recipes])
->attachments([$this->request->data['photo'] => $this->request->data['photo']['tmp_name']])
->emailFormat('html')
->to('xx#xx.com')
->from($user['email'])
->send();
Text inputs are well stored and sent. But no image attached in my email...
What's wrong?
Thanks!
I was stuck here to i got it, in your create form add
'enctype'=>'multipart/form-data'
So it should be
echo $this->Form->create($email, ['enctype'=>'multipart/form-data']);
This is added in the other controller by default but when you use a model less form it doesn't do this.
I have a page where there are multiples forms generated with the FormHelper that aim at modifying the same entity. The problem is: validation errors will show up on both forms.
With cakephp 2, this problem was solved by extending Models (see : http://bakery.cakephp.org/articles/RabidFire/2010/06/26/multiple-forms-per-page-for-the-same-model ).
However I don't see how to do this with cakephp 3.
EDIT: i'm gonna describe more precisely what I'm trying to do.
I have two forms on the same page. The first one enables a user to change his email address, the other one to change his password.
Both forms are created with the Form helper and the same user entity.
In both forms, there is a field where the user should enter his current password (as a security measure). A validator will check if the password entered is correct before letting the email or the password to be changed.
Problem: let's say the user tries to change his email but typed a wrong password, the "wrong password" message will appear on both forms.
This is sort of an edge case that the FormHelper is not ready to handle graciously. But this is a solution, you will need 2 entities:
$user = $this->Users->get($id);
$user->unsetProperty('password');
$clonedUser = clone $user;
$this->set(compact('user', 'clonedUser'));
In your view, you build your forms in a way that you can detect which entity you should pass:
echo $this->Form->create($this->request->data('_form1') ? $user : $clonedUser);
... fields here
echo $this->Form->hidden('_form1', ['value' => 1]);
echo $this->Form->create($this->request->data('_form2') ? $user : $clonedUser);
... fields here
echo $this->Form->hidden('_form2', ['value' => 1]);
What the above code does is detecting which of the forms was previously submitted and render the form with either the empty cloned entity or the entity having the errors.
Stumbled upon this because I had the same requirement. I would go with José but move the logic to the Controller instead:
$callback = $this->Inquiries->newEntity();
$inquiry = $this->Inquiries->newEntity();
if ($this->request->is('post')) {
if ($this->request->data('_type') === 'callback') {
$callback = $this->Inquiries->patchEntity($callback, $this->request->data, ['validate' => 'callback']);
$entity = &$callback;
} elseif ($this->request->data('_type') === 'inquiry') {
$inquiry = $this->Inquiries->patchEntity($inquiry, $this->request->data);
$entity = &$inquiry;
}
if (!$entity->errors()) {
// do stuff here
}
}
$this->set(compact('callback', 'inquiry'));
Pass the type of the form:
echo $this->Form->input('_type', ['type' => 'hidden', 'value' => 'inquiry']);
Here I have used cakephp js helper to send data,After insert One data I need this last id for farther work.Here I have tried bellow code in Addcontroller
if ($this->Patient->save($this->request->data)) {
$lastid=$this->Patient->getLastInsertId();
$patient=$this->Patient->find('all',array(
'conditions'=>array('Patient.id'=>$lastid ),
'recursive' => -1
));
$this->set('patient', $patient);
}
In add.ctp I have tried bellow code but I haven't get last id here.
<?php foreach ($patient as $patient): ?>
<?php echo h($patient['Patient']['id']); ?>
<?php endforeach; ?>
Method getLastInsertId() return id of just saved records.
If you need this id in your view just after save, you must first set that variable in your controller like $this->set(compact('lastid','patient'); and then use in view <?php echo $lastid; ?>
use
if ($this->Patient->save($this->request->data)) {
$id = $this->Patient->id;
$patient=$this->Patient->find('all',array('conditions'=>array('Patient.id'=>$id),'recursive' => -1));
$this->set->('patient', $patient);
//If you are saving the record with ajax which it looks like you
//might be from your question you will need the following instead
//of $this->set->('patient', $patient); try:
return json_encode($patient);
You will then also need to update your js ajax call, you will have a json array to decode so parse it with jquery and append it back into your view.
Cake will always give you the id of record you have just saved, by simply adding $id = $this->MyModel->id; You can use the id to query for the record.
Try below code:
In controller:
$lastid=$this->Patient->getLastInsertId();
$this->set(compact('lastid','patient');
Then use $lastid in View file.
In controller:
$lastid=$this->Patient->getLastInsertId();
$patient['Patient']['last_id'] = $lastid;
then use $patient['Patient']['last_id'] in your view file.
I have created a another profile student, and added a field called class. i want to display this form including the class filed.
How to display the student registration form .. Please help
i have used below code in block
<?php
print drupal_render(drupal_get_form('user_register_form'));
$profile = profile2_load_by_user($account);
print drupal_render(field_view_field('profile2', $profile['Student'], 'field_class'));
?>
I am using an Account Controller which doesnt have its own table but uses User Model.
All works fine except - when I validate any form. It says validation fails (when I try to fail the validation to check) but doesnt throw the error below the field
View
<?php echo $this->Form->input('id'); ?>
<label for="UserPassword">New Password:</label>
<?php echo $this->Form->text('password', array('type' => 'password', 'value' => 'harsha')); ?><em>Password must be min 6 characters.</em> <?php echo $form->error('password'); ?>
Controller Action
if($this->User->saveField('password', $this->data['User']['password'], array('validate' => 'first'))) {
$this->Session->setFlash('Password has been changed.', 'flash-success');
} else {
$this->Session->setFlash('There was some problem with our system. Please try after some time.', 'flash-warning');
}
Try debug()ing the contents of $this->validationErrors in your view, as well as $this->data in your controller just after a form submission. This should give you a lot more information to work from.
I suspect that your problem is Cake is building form inputs based on the wrong model -- building form fields for Account.id and Account.password instead of User.id and User.password. This is because FormHelper takes its default model from the controller/view it's invoked from, which in your case appears AccountsController.
In order to generate the User.id and User.password fields your controller's submission handling expects, you'll need to prepend User. in your FormHelper calls. Thus:
$this->Form->input('User.id');
$this->Form->text('User.password');
Have you tried:
echo $session->flash();
Note that whatever the manual says, it returns, not echoes. I logged this a while back and it has been changed in the 1.3 manual, but not the 1.2.
Hi you who's asking If you want to show error-message that return from UserModel's validate So you can add line code bellow after input form password
<?php
if ($this->Form->isFieldError('password')) {
echo $this->Form->error('password', array('class' => 'error'));
?>
and if you want to show error-message that set by method setFlash
you must redirect page and then use $this->Session->flash('flash-name') in page you want to show it
<?php
//in UsersController
$this->Session->setFlash('message here', 'flash-name');
//in view
echo $this->Session->flash('flash-name');
?>
Good luck!