Link to home
Start Free TrialLog in
Avatar of MostHated
MostHatedFlag for United States of America

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 :

<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>

Open in new window


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');
        }

Open in new window


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!


User generated image
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MostHated

ASKER

Thanks for the reply, I appreciate it. That should be easy enough since I already have a listing of all of the form names in the actual email, I would just have to write out the name conversion. I will give that a try now and report back.

Thanks!
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)?
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.
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.