Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Multiple inputs send via ajax
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Multiple inputs send via ajax

LeviLevi Member

I have interesting problem in my hands, can't wrap my head how to solve it. Seeking for knowledgeable person to help.

I have this construct in HTML/Smarty and Jquery:

https://pastebin.com/UiBLY7Xd

My task is to send multiple inputs in table as comma separated arrays to PHP like this:

[
  0 => ["name", "ttl", "type", "prio", "content"], 
  1 => ["name", "ttl", "type", "prio", "content"], 
  2 => ["name", "ttl", "type", "prio", "content"],
  <...>
]

Anyone knows the best approach how to resolve this? I can't even properly google this problem...

Comments

  • exception0x876exception0x876 Member, Host Rep, LIR
    edited January 2022

    Just use the PHP associative array syntax for your form names i.e. <input name="record[ttl][]" />

    Then use jQuery form serialization to send the data through.

  • @exception0x876 said:
    Just use the PHP associative array syntax for your form names i.e. <input name="record[ttl][]" />

    Then use jQuery form serialization to send the data through.

    How to separate each iteration of inputs into separate arrays in PHP?

  • exception0x876exception0x876 Member, Host Rep, LIR

    Add an index to your for loop and then use it for input names <input name="record[<?php echo $i; ?>][ttl]" />

    Thanked by 1Levi
  • make them as an javascript object, then use JSON.stringify()

Sign In or Register to comment.