Jump to content

Input value is HTML element


dps123
 Share

Recommended Posts

This is probably really simple but can't figure it out. note_page_id is a hidden field with the page id as it's value.

$note_page_id = wire('sanitizer')->text($input->post->note_page_id);

$note_page_id is an [object HTMLInputElement] rather than the value. Why is it not returning the value like it normally would? How can I get the value?

Link to comment
Share on other sites

Not sure if I can understand what you have done, nor how you have done it, nor what you are after. ??

Looking into my glass ball,  ;)  I would say:

First, inspect the raw value of $input->post->note_page_id

<?php
echo "<pre>";
my_var_dump($input->post->note_page_id);
die();

If you expect an numeric ID and it does contain more than that, you should change your html form field accordingly.

And if you get a numeric value, you can sanitize with int, not text. Or you simply use PHPs typecasting via (int) or intval().

$note_page_id = (int)$input->post->note_page_id;
Link to comment
Share on other sites

It's just a hidden form field:

<input name="note_page_id" type="hidden" id="note_page_id" value="<?= $page->id; ?>" />

The problem with doing:

echo "<pre>";
my_var_dump($input->post->note_page_id);

is that it's being handled by an ajax script, so nothing appears.

Link to comment
Share on other sites

You can look at the returned info in the network tab of the developer tools even if it's an ajax call. But clearly this shouldn't be a php issue, because '[object HTMLInputElement]' is a string javascript does spit out when you try to cast an html node to a string. Therefore please check your javascript to ensure the correct value is actually being sent.

Link to comment
Share on other sites

Have just found that if I change my data string to:

var dataString = 'comment='+comment+'&note_page_id='+note_page_id.value;

the note_page_id is the correct value. But I don't normally have to do that. It normally just returns the value from the input name variable.

Link to comment
Share on other sites

Firstly. Please use the code block option for all the code snippets you're posting. I've edited you posts above. This makes things a great deal more pleasing to read. 

About you javascript issue. From such a small snippet it's hard so say anything about it, especially as the part is missing, where you get the value of the input field and save it to your variable. 

Your second question is easily answered with a yes. You can do that. More info about that can be found here: http://php.net/manual/en/language.variables.variable.php

Link to comment
Share on other sites

Not sure what you mean by 'especially as the part is missing, where you get the value of the input field and save it to your variable.' This is where I'm grabbing the value of the note_page_id form field and assigning it to the note_page_id variable:

var dataString = 'comment='+comment+'&note_page_id='+note_page_id.value;

It works now that I've specified I want the value, but strange that I don't have to do the same with the comment variable, nor any others that I've used before.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...