/    Sign up×
Community /Pin to ProfileBookmark

Form problem text-area and option

hi,
I have problem with option as always is giving me NULL value.

btw this new forum is rubbish as I can send my script for debug.

‘[+Mr+]’ => ($form->title == ‘Mr’) ? (‘selected’):”,
‘[+Mrs+]’ => ($form->title == ‘Mrs’) ? (‘selected’):”,
‘[+Miss+]’ => ($form->title == ‘Miss’) ? (‘selected’):”,
‘[+Ms+]’ => ($form->title == ‘Ms’) ? (‘selected’):”,

I use to had echo (‘selected’) in my ternary condition but it always giving me parse error echo T_cho
title is variable that it should be set in the class.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@marcellioauthorJun 19.2018 — It doesn't move value into my clean array

public function submit_title(){

if(isset($this->clean_arr['title'])){

return $this->title = htmlentities($this->clean_arr['title'],ENT_QUOTES,'UTF-8');

}else{

return $this->title = 'NULL';

}

}

//check option field if has the right value

public function title($title_field){

if ($title_field){

if(in_array($title_field,$titles)){

return $this->clean_arr['title'] = $title_field;;

}else{

$this->errors_detected = true;

return $this->errors_arr['title'] = "Please choose your title.";

}

}

}

it always giving me the error message
Copy linkTweet thisAlerts:
@rootJun 19.2018 — @marcellio#1593109 putting echo in a ternery will cause an error, you obviously have an issue with understanding their use.

and please use </code></span></C> your code in here <C><span><code> when posting code like so...
'[+Mr+]' =&gt; ($form-&gt;title == 'Mr') ? ('selected'):'',
'[+Mrs+]' =&gt; ($form-&gt;title == 'Mrs') ? ('selected'):'',
'[+Miss+]' =&gt; ($form-&gt;title == 'Miss') ? ('selected'):'',
'[+Ms+]' =&gt; ($form-&gt;title == 'Ms') ? ('selected'):'',


And I have to ask, what is that for? It is completely meaningless IMHO you could do this simply with an in_array() and an array of titles that you test the passed form title with to see if its one your form accepts.
$titles = array("Mr","Mrs","Miss","Ms","Dr","Rev");
if( in_array($form-&gt;title, $titles ) ){
// do something
}

I suggest that you post the code that is causing you a problem and use the forumBB Code tags please.
Copy linkTweet thisAlerts:
@marcellioauthorJun 19.2018 — I have that code in my function title just check above but I will rewrite with your code

<i>
</i>public $titles = ['Mr', 'Mrs', 'Miss', 'Ms'];

public function title($title_field){
if ($title_field){
if(in_array($title_field,$titles)){
return $this-&gt;clean_arr['title'] = $title_field;;
}else{
$this-&gt;errors_detected = true;
return $this-&gt;errors_arr['title'] = "Please choose your title.";
}
}
}


public function submit_title(){
if(isset($this-&gt;clean_arr['title'])){
return $this-&gt;title = htmlentities($this-&gt;clean_arr['title'],ENT_QUOTES,'UTF-8');
}else{
return $this-&gt;title = 'NULL';
}
}


this is HTML template code

&lt;label for="title"&gt;Title:&lt;/label&gt;
&lt;select name="title" id="title"&gt;
&lt;option value="NULL" selected="selected"&gt;Please select&lt;/option&gt;
&lt;option [+Mr+]
value="Mr"&gt;Mr&lt;/option&gt;
&lt;option [+Mrs+]
value="Mrs"&gt;Mrs&lt;/option&gt;
&lt;option [+Miss+]
value="Miss"&gt;Miss&lt;/option&gt;
&lt;option [+Ms+]
value="Ms"&gt;Ms&lt;/option&gt;
&lt;/select&gt;

but it always return error_arr.

Look at the website http://mzacharias.co.uk/index.php?page=contact

on the top I have left two arrays first is error array with values and second is clean array values

title doesn't moved into clean array after is set but instead always giving error arr please choose title. Have a look
Copy linkTweet thisAlerts:
@rootJun 19.2018 — IDK what this &lt;option [+Mr+]
value="Mr"&gt;Mr&lt;/option&gt;
is all about but a form consists of the &lt;form tag, the option in the select have a value attribute so that line should be &lt;option value="Mr"&gt;Mr&lt;/option&gt; and other lines the same.

Then your receiving form needs to access the field and to do that, you have to have a form, without a form.

Then you need the right attributes for the form.
Copy linkTweet thisAlerts:
@marcellioauthorJun 19.2018 — &lt;option &lt;?php if($titles == 'Mr') {
echo ("selected");
}?&gt;
value="Mr"&gt;Mr&lt;/option&gt;


this is the original code that works but the file is php. I have created file of HTML template and I passing values or whatever I what to show on the page throughout placeholders. My placeholder I have diced to mark them as [+ whatever I what to be replace here. +]

therefore if you look at the original code and my code that is what i'm trying to achieve by passing throughout placeholder from php file to HTML file. Unless there is another option how to achieve this but I can't find anything on google. Therefore I though someone here might have an idea.

so &lt;option [+Mr+] this is just placeholder that is replaced by the code from here '[+Mr+]' =&gt; ($form-&gt;title == 'Mr') ? ('selected'):'',

but when I was using echo I had always error but now without echo it doesn't work at all and always is return NULL value which please choose your title. That this make sense?
Copy linkTweet thisAlerts:
@rootJun 20.2018 — &lt;option &lt;?php if($titles == 'Mr') {
echo ("selected");
}?&gt;
value="Mr"&gt;Mr&lt;/option&gt;
is outputting a form element that has a pre-selected input, but how do you know when your generating the form what the gender is? IMHO a pointless exercise, you should just output one selected field, usually one labelled up like &lt;option value="-1" selected&gt;Please Select&lt;/option&gt;
&lt;option value="mr"&gt;Mr&lt;/option&gt;
&lt;option value="mrs"&gt;Mrs&lt;/option&gt;
&lt;option value="ms"&gt;Ms&lt;/option&gt;
.. and so on.

If this has been selected on a previous page, then why on earth are you outputting the form again?
×

Success!

Help @marcellio spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...