MostHated
asked on
Yii Framework - PHP - Submit and email a form with placeholder displayed instead of the field name?
Hello all,
I have been working on an application form which is pretty long, upwards of 100 fields and I have it working and all, I just need to try and make it a bit more readable but trying to do it as easy as possible. You can see in the pic below, it comes through showing the fields name, which some of them are not really understandable to people, such as yib being Years in Business, and yal being Years At Location. I have all the placeholders of the form filled out and was wondering if it were possible to use a script to take those placeholders and replace it on my email template with those values instead.
Currently, the way my email template is quite simple as you will see :
The code I am using to submit it is :
Is there a way I can try and capture those placeholder values and either show them in addition to the name (if need be) or replace the name value with the placeholder value with a looping script and not having to try to copy and paste them all?
Thanks!
I have been working on an application form which is pretty long, upwards of 100 fields and I have it working and all, I just need to try and make it a bit more readable but trying to do it as easy as possible. You can see in the pic below, it comes through showing the fields name, which some of them are not really understandable to people, such as yib being Years in Business, and yal being Years At Location. I have all the placeholders of the form filled out and was wondering if it were possible to use a script to take those placeholders and replace it on my email template with those values instead.
Currently, the way my email template is quite simple as you will see :
<html>
<body>
<table rules="all" style="border-color: #666;" cellpadding="10">
<?php foreach ($emailArray as $name => $value) { ?>
<tr>
<td>
<strong><?php echo $name; ?></strong>
</td>
<td>
<?php echo $value; ?>
</tr>
<?php }; ?>
</table>
</body>
</html>
The code I am using to submit it is :
public function actionApplication()
{
if(isset($_POST['email'])) {
//die("<pre>".print_r($_POST,true)."</pre>");
Yii::app()->theme = "newlanding";
//$email = trim($_POST['email']);
$emailArray = $_POST;
$subject = 'New Vendor Application ';
$body = $this->renderPartial("/site/_applicationEmail",array("emailArray"=>$emailArray),true);
Email::sendMail("me@email.com",$subject,$body);
$this->redirect(Yii::app()->createUrl("/Site/Application"));
}
Yii::app()->theme = "newlanding";
$this->render('application');
}
Is there a way I can try and capture those placeholder values and either show them in addition to the name (if need be) or replace the name value with the placeholder value with a looping script and not having to try to copy and paste them all?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
For some reason when I submit this, it is not working. I can not quite figure out why. I get just a server 500 error when I did it the way you mentioned. Trying to figure it out now.
-- Edit, I can not seem to figure out what is wrong here. https://hastebin.com/naxufiwitu.xml
Any ideas? I am wondering if it has anything to do with the fact that I did not include every single field in the array at the top, there were a good few whos names already were correct (things with just single word names)?
-- Edit, I can not seem to figure out what is wrong here. https://hastebin.com/naxufiwitu.xml
Any ideas? I am wondering if it has anything to do with the fact that I did not include every single field in the array at the top, there were a good few whos names already were correct (things with just single word names)?
Can you try making the changes incrementally.
Go back to what you had - that worked.
Then just add this line
<?php $formLabels = []?>
Test that - if that works then add the bit between the []
If that works then make the code change to the loop.
See where it breaks.
Go back to what you had - that worked.
Then just add this line
<?php $formLabels = []?>
Test that - if that works then add the bit between the []
If that works then make the code change to the loop.
See where it breaks.
ASKER
Looks like it was something silly, the $ was missing from <strong><?php echo $formLabels[$name]; ?></strong>. Got it working well, I really appreciate it!
You are welcome.
ASKER
Thanks!