Jump to content
dps123

Input value is HTML element

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?

Share this post


Link to post
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;

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ngrmm
      I have a page with a table. Each table row has a page-reference field and a checkbox.
      The Page sends emails to all users (page-refrence->email-field) and change the value of the checkbox in a row to 1.
      It works with this:
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?> But i have to use a variable in my emailbody.inc which i'm able to get in the table-loop.
      So i do the including of the body inside my loop. But this doesn't work anymore. Page sends out the emails but is unable to change the value of the checkbox.
      I get no errors!
      I'm using ProTable
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?>  
    • By jds43
      Hello,
      I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results.
      I hope this isn't too vague.
       
    • By Hubris
      Hi there!
      I'm using some page reference fields to create lists of tags, categories, years, etc.. I'm able to find the pages like so:
      $pages->find("template=project, {$filter}={$page->title}"); Which dynamically does something like: 
      $pages->find("template=project, tags=Experimental"); Only if the value (the page name, like "Experimental") starts with letters. If it starts with numbers, find returns nothing.
      Why is this and how can I fix it?
    • By pwFoo
      With JS fetch() it is a bit tricky to get for example $_POST populated (params need to be FormData / forms), but would it possible to get PW $input (get, post, urlSegments, queryString) working for fetch requests?
      Is there a fix / hook / workaround to solve it PW side?
    • By gonzz
      I'm doing an artist site and they want to be able to upload a large .tiff to their portfolio. I need to keep to a copy of the original file in the server for the art distributers, and of course serve jpg in the web front end.
      I had the idea of extending the file or image upload input so that if the image is tiff, keep it, and also convert it to jpg, so I could access through something like $image->originalUrl or $image->size(100, 100)->url 
      I was wondering if you thought this a good idea, or if i'm over-engineering something that could be done simply. Also, I've never extended an input, so any examples are welcome.
      Thanks!
×
×
  • Create New...