Jump to content

Recommended Posts

Posted

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?

Posted

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

How did you add note_page_id to the page, and how does its rendered markup look like?

Posted

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.

Posted

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.

Posted

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.

Posted

Whilst I've got your attention ;) If I've got a variable

$var = 'my_field';

Can I then use that in the API to specify a page field when setting it's value:

$p->$var = 'something';
Posted

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

Posted

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.

Posted

note_page_id is a variable, which does need to be defined somewhere. That's the part which is missing, which could lead to an answer about why you need to include its value. 

  • Like 1

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
×
×
  • Create New...