php - If statement in variable -
i've seen many posts problems couldn't find right answer worked out. problem have code says if ... empty, make variable ... (see code below). variable form , in form have things name, message etc. want placeholder of name, if user logged in name, saved in database. code:
$action = isset($_post["action"]) ? $_post["action"] : ""; if (empty($action)) { // send contact form html $output = "<div style='display:none'> <div class='contact-top'></div> <div class='contact-content'> <h1 class='contact-title'>stuur een bericht voor hulp:</h1> <div class='contact-loading' style='display:none'></div> <div class='contact-message' style='display:none'></div> <br><br><form action='#' style='display:none'> <input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder='naam*' /><br><br> <input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' placeholder='email*' /><br><br>";
and want doesn't work:
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder=', " if (logged_in() === true) {echo $user_data["name"] } else { echo 'naam'; } " ,' /><br><br>
hope can help, in advance,
paul
(naam = name in language)
you forgot surround if in <?php
tags
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder="<?php if (logged_in() === true) { echo $user_data["name"]; } else { echo 'naam'; } ?>" /><br><br>
ps conditions not working inside strings, if need outside of html template, need before string:
$name = 'naam'; if (logged_in() === true) { $name = $user_data["name"]; } $html = "<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' placeholder="{$name}" /><br><br>";
Comments
Post a Comment